On Thu, Sep 12, 2002 at 02:57:57PM +0200, Ren Hoek wrote:
> I'm working on Linux.. I saw that I made a very bad mistake in my program.. I put 
> the timeout in front of my loop, instead of inside.. :(

That's a Linux quirk with "select()", not specific to libpcap.

"select()", on Linux, modifies the timeout structure, as per the
"select()" man page on, at least, RH Linux 7.3 (although that's probably
the man page used in many, perhaps most, Linux systems):

        
http://www.FreeBSD.org/cgi/man.cgi?query=select&apropos=0&sektion=0&manpath=Red+Hat+Linux%2Fi386+7.3&format=html

"On Linux, the function select modifies timeout to reflect the amount of
time not slept; most other implementations do not do this.  This causes
problems both when Linux code which reads timeout is ported to other
operating systems, and when code is ported to Linux that reuses a struct
timeval for multiple selects in a loop without reinitializing it. 
Consider timeout to be undefined after select returns."

> if(pcap_setnonblock(pcap, 1, errbuf) == 1)
>    {
>    fprintf(stderr, "Could not set device \"%s\" to non-blocking: %s\n", device, 
> errbuf);
>    exit(1);
>    }

To quote the libpcap man page:

       pcap_setnonblock()  puts a capture descriptor, opened with
       pcap_open_live(), into ``non-blocking'' mode, or takes  it
       out  of  ``non-blocking''  mode,  depending on whether the
       nonblock argument is non-zero or zero.  It has  no  effect
       on  ``savefiles''.   If  there is an error, -1 is returned
                                                   ^
       and errbuf is filled in with an appropriate error message;
       otherwise,  0  is  returned.

so that should be

        if(pcap_setnonblock(pcap, 1, errbuf) == -1)
            {
                ...
            }

(i.e., check against -1, not 1).
-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe

Reply via email to