c - initialization makes integer from pointer without a cast and 2 more compiler errors
Solution 1
You should do
int LEN = *args;
args is a pointer, *args is the value pointed by it. Also, you shouldn't put a u_char into an int.
For nthol: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740069(v=vs.85).aspx
Solution 2
You can use atoi()
function to convert char* to int.
About the link error about pthread, try put -lpthread
on your compile command
youjustreadthis
Updated on August 19, 2020Comments
-
youjustreadthis over 3 years
so I'm getting this warning:
initialization makes integer from pointer without a cast
in the following piece of code:
void receive(u_char *args, const struct pcap_pkthdr *pkthdr, const u_char *buffer) { const int one = 1; int LEN = args; /* THIS IS THE LINE */ struct ipheader *ip; struct tcpheader *tcp;
and to be honest little newbie me is not sure what to do as almost all searches return
makes pointer from integer
.I'm also getting these compiler messages:
/tmp/cci6u7NH.o: In function `main': ChannelBunny.c:(.text+0x448): undefined reference to `pthread_create' ChannelBunny.c:(.text+0x4b7): undefined reference to `pthread_join' /tmp/cci6u7NH.o: In function `receive': ChannelBunny.c:(.text+0xcb6): undefined reference to `nthol' ChannelBunny.c:(.text+0xcdf): undefined reference to `nthol' collect2: ld returned 1 exit status
got rid of a similar pcap problem by using
-l pcap
but that didn't work for the other two. It just returned:gcc: pthread: No such file or directory gcc: nthol: No such file or director
I'm guessing I have to download something? or is there another command I have to use. (I'm using Backtrack5 if that's of any use to you).
-
Tim Post over 11 yearsI'm speaking as a C programmer here, not a moderator. Please do not recommend the use of
atoi()
,strtol()
is much, much safer. -
youjustreadthis over 11 yearsNever used atoi() before, but there is a pcap_loop function further down that I didn't include here which I believe is expecting a char*. wouldn't atoi() conflict with that?
-lpthread
worked brilliantly btw :) @TimPost how would that look in my example? -
Tim Post over 11 years@youjustreadthis Just
LEN = strtol(args, NULL, 0)
, the spec is quite informative. But I'm not sure whyargs
isu_char
? -
mask8 over 11 years@youjustreadthis what do you expect args to be? @TimPost I agree. if you are not sure what you are passing to
atoi
-
mask8 over 11 years@youjustreadthis oh, so you are receiving a pointer at args, which you actually pass to
pcap_loop()
what are you passing in thepcap_loop()
? it's up to what you expect to have inLEN
-
youjustreadthis over 11 years@TimPost well i'm going by an example program I found so I could try to put together a 3 way tcp connection. And that is how it looked like. I was alsu under the impression that
(pcap_loop(pd, -1, receive, (u_char *) &dl_len) < 0)
requires a u_char in the recieve function. Got it to compile now so with any (lots considering my skills haha) luck it'll work, but we'll see.