3

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).

youjustreadthis
  • 622
  • 3
  • 9
  • 24

3 Answers3

9

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

Husker14
  • 586
  • 1
  • 5
  • 7
3

You can use atoi() function to convert char* to int.

About the link error about pthread, try put -lpthread on your compile command

mask8
  • 3,560
  • 25
  • 34
  • I'm speaking as a C programmer here, not a moderator. *Please* do not recommend the use of `atoi()`, `strtol()` is [much, much safer](http://stackoverflow.com/questions/2729460/why-do-i-get-this-unexpected-result-using-atoi-in-c/2729534#2729534). – Tim Post Aug 18 '12 at 15:44
  • Never 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? – youjustreadthis Aug 18 '12 at 15:46
  • 1
    @youjustreadthis Just `LEN = strtol(args, NULL, 0)`, the [spec](http://pubs.opengroup.org/onlinepubs/007908799/xsh/strtol.html) is quite informative. But I'm not sure why `args` is `u_char` ? – Tim Post Aug 18 '12 at 15:55
  • @youjustreadthis what do you expect args to be? @TimPost I agree. if you are not sure what you are passing to `atoi` – mask8 Aug 18 '12 at 15:58
  • @youjustreadthis oh, so you are receiving a pointer at args, which you actually pass to `pcap_loop()` what are you passing in the `pcap_loop()`? it's up to what you expect to have in `LEN` – mask8 Aug 18 '12 at 16:05
  • @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. – youjustreadthis Aug 18 '12 at 16:11
0

You pass a pointer

u_char *args

You try to assign it to an integer

int LEN = args;

The error message says this.

"makes integer from pointer"

The real question is what do you think args is? Just from looking, I'd guess it holds some arguments, not the length of some arguments?

Josh Petitt
  • 9,371
  • 12
  • 56
  • 104