Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8379833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:17:48+00:00 2026-06-09T16:17:48+00:00

I am getting this warning: cast to pointer from integer of different size when

  • 0

I am getting this warning:

cast to pointer from integer of different size

when attempting to compile my program. This particular piece of code is pretty much lifted from an example TCP connection program and I am just a hobby programmer, so I’m guessing the solution is quite obvious, yet it’s driving me mad.

My understanding of the pcap_loop function is that the u_char * points to the first argument of the recieve function, right? If that is the case why do get a warning?

As I’m not really sure what’s wrong i’ve included what I believe are the relevant functions in their entirety, and I really hope some of you will find it in you to help me out here.

void receive(u_char *args, const struct pcap_pkthdr *pkthdr, const u_char *buffer)
{
const int one = 1;
int LEN = *args;        
struct ipheader *ip;
struct tcpheader *tcp;

ip = (struct ipheader *)(buffer + LEN);
tcp = (struct tcpheader *)(buffer + LEN + sizeof (struct ipheader));

printf("%d\n", LEN);

printf("Packet received. ACK number: %d\n", ntohl (tcp->tcph_seqnum));
printf("Packet received. SEQ number: %d\n", nthol (tcp->tcph_acknum));
s_seq = nthol (tcp->tcph_seqnum);

send_syn_ack(s_seq, dip, sip, dport, sport);    

sleep(100);
}

void capture()
{
pcap_t *pd;
bpf_u_int32 netmask;
bpf_u_int32 localnet;
char *filter = ("ip dest host %s", dstip);      
char *dev = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program filterprog;
int dl = 0, dl_len = 0;

if ((pd = pcap_open_live(dev, 1514, 1, 500, errbuf)) == NULL) 
    {           
        fprintf(stderr, "cannot open device %s: %s\n", dev, errbuf);
        exit(1);
    }

pcap_lookupnet(dev, &localnet, &netmask, errbuf);
pcap_compile(pd, &filterprog, filter, 0, localnet);
if (pcap_setfilter(pd, &filterprog) == - 1)
    {
        fprintf(stderr, "cannot set pcap filter %s: %s\n", filter, errbuf);
        exit(1);
    }

pcap_freecode(&filterprog);
dl = pcap_datalink(pd);

switch(dl) {
    case 1:
        dl_len = 14;
        break;
    default:
        dl_len = 14;
        break;
}       

if (pcap_loop(pd, -1, receive, (u_char *)dl_len) < 0)   /* THIS IS THE LINE IN QUESTION */
    {
        fprintf(stderr, "cannot get raw packet: %s\n", pcap_geterr(pd));
        exit(1);
    }
}

Thanks a lot both of you! @pb2q I am a bit confused. when you say:

you’ll need to pass it’s address, and make sure that the variable is dynamically allocated or remains in scope >when the callback executes.

I am afraid I’m not sure how that translate into code in this example, and I do not wish for the code to be sloppy, although what has been suggested below seemed to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:17:50+00:00Added an answer on June 9, 2026 at 4:17 pm

    The function is expecting a pointer to user data, to pass through to a callback function. Your supplied argument is an integer, and not a pointer, and it will be interpreted as a memory address if it’s used in the callback. This isn’t what you want.

    If you want to pass dl_len through to the callback, and be able to look at it’s value (looks like it’s only ever 14), you’ll need to pass it’s address, and make sure that the variable is dynamically allocated or remains in scope when the callback executes.

    Pass a pointer like so – note the &:

    if (pcap_loop(pd, -1, receive, (u_char *) &dl_len) < 0) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a warning: Return makes pointer from integer without a cast for this
I am getting this warning, warning: assignment makes pointer from integer without a cast,
gcc 4.4.4 c89 warning assignment makes integer from pointer without a cast **devices =
I'm getting this warning Implicit conversion from enumeration type 'UIViewAnimationCurve' to different enumeration type
I am getting this warning: warning: comparison between pointer and integer when doing the
I am getting this warning from FxCop: 'RestartForm' contains field 'RestartForm.done' that is of
I'm getting this warning from sccanf() : ../../../../ext/oedipus/oedipus.c:211: warning: conversion lacks type at end
I am getting this warning even though everything functions perfectly. Here is the code
I'm getting a Type safety: Unchecked cast from Object to ArrayList warning on the
i am getting this warning while using lib2xml in my code. warning: Unable to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.