1
votes

With the following code, I get this error when I run the executable file:

...
dev = pcap_lookupdev(errbuf);
if(dev == NULL)
{
    printf("%s\n",errbuf);
    exit(1);
}
printf("DEV: %s\n",dev);
descr = pcap_open_live(dev,BUFSIZ,0,-1,errbuf);
if(descr == NULL)
{
    printf("pcap_open_live(): %s\n",errbuf);
    exit(1);
}
packet = pcap_next(descr,&hdr);

if(packet == NULL)
{
    printf("Didn't grab packet\n");
    exit(1);
}
...

And the error:

pcap_open_live(): gbeth0: BIOCSRTIMEOUT: Invalid argument

When I change

descr = pcap_open_live(dev,BUFSIZ,0,-1,errbuf);

to

descr = pcap_open_live(dev,BUFSIZ,0,1,errbuf);

sniffer does not grab anything and the program exit with this error: Didn't grab packet and when I change 1 to 0 it does not grab anything but with errors. What should I do?

1

1 Answers

3
votes

-1 is NOT a valid timeout argument to pcap_open_live() on any platform.

0, as a timeout argument, may behave differently on different platforms, and is not recommended.

And pcap_next() is not guaranteed to wait forever for a packet to arrive; it might return NULL if the timeout expires. If you want to capture at least one packet, try looping until pcap_null() doesn't return NULL.