[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tcpdump-workers
Subject:    Re: [tcpdump-workers] libpcap-2005.06.25/savefile.c
From:       Guy Harris <guy () alum ! mit ! edu>
Date:       2005-06-26 6:23:33
Message-ID: 42BE49E5.7040305 () alum ! mit ! edu
[Download RAW message or body]

Phil Wood wrote:
> It  works, but I think args 2 and 3 (of 4) to fread are swapped.
> Unless it forces the kernel to read a character at a time?
> 
> Line 1048:   amt_read = fread((char *)&hdr, 1, sizeof(hdr), fp);

That call says "read 'sizeof(hdr)' 1-byte entities, and return the 
number of 1-byte entities you read on success, and return EOF on failure".

"fread()" isn't guaranteed to make "nmemb" requests, of size "size", of 
the kernel.  The big difference between "1, sizeof(hdr)" and 
"sizeof(hdr), 1" is that in the first case if less data is available 
than "sizeof(hdr)" bytes the first call will return the number of bytes 
read, while the second call will presumably return 0.  The first call 
lets libpcap report how many bytes were actually read (for what that's 
worth), while the second call doesn't.
-
This is the tcpdump-workers list.
Visit https://lists.sandelman.ca/ to unsubscribe.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic