Your message dated Tue, 16 Jun 2009 15:17:47 +0200
with message-id <[email protected]>
and subject line Re: Bug#523633: libpcap0.8-dev: Using pcap_setdirection can
cause pcap_next to fail
has caused the Debian Bug report #523633,
regarding libpcap0.8-dev: Using pcap_setdirection can cause pcap_next to fail
to be marked as done.
This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.
(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)
--
523633: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523633
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: libpcap0.8-dev
Version: 0.9.8-5
Severity: important
With the following program, about 50% of the time the pcap_next fails
with "Error reading from eth0".
If you comment out the pcap_setdirection line you never get this, data is
always read.
#include <pcap.h>
main()
{
pcap_t *pcap;
const u_char *buffer;
struct pcap_pkthdr header;
char errbuf[PCAP_ERRBUF_SIZE];
pcap = pcap_open_live("eth0", BUFSIZ, 1, 1000, errbuf);
if(pcap == NULL) {
fprintf(stderr, "eth0: %s\n", errbuf);
return 1;
}
pcap_setdirection(pcap, PCAP_D_IN);
buffer = pcap_next(pcap, &header);
if(buffer == NULL) {
fputs("Error reading from eth0\n", stderr);
pcap_close(pcap);
return 2;
}
pcap_close(pcap);
printf("Read %d bytes\n", header.len);
return 0;
}
-- System Information:
Debian Release: 5.0
APT prefers stable
APT policy: (500, 'stable')
Architecture: i386 (i686)
Kernel: Linux 2.6.26-1-686 (SMP w/2 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libpcap0.8-dev depends on:
ii libc6-dev 2.7-18 GNU C Library: Development Librari
ii libpcap0.8 0.9.8-5 system interface for user-level pa
libpcap0.8-dev recommends no packages.
libpcap0.8-dev suggests no packages.
-- no debconf information
--- End Message ---
--- Begin Message ---
Hi,
Nigel Horne <[email protected]> writes:
> buffer = pcap_next(pcap, &header);
> if(buffer == NULL) {
> fputs("Error reading from eth0\n", stderr);
> pcap_close(pcap);
> return 2;
> }
This code is wrong, pcap_next() can return NULL even if no error
occurred, for example if it received a packet that didn't match the
filter (which is what is happening for you, it returns NULL when it
receives a packet in the wrong direction).
See pcap_next(3):
pcap_next() returns a pointer to the packet data on success, and
returns NULL if an error occured, or if no packets were read from
a live capture (if, for example, they were discarded because they
didn’t pass the packet filter, [...]) Unfortunately, there is no
way to determine whether an error occured or not.
I suggest that you use pcap_dispatch() instead.
--
Romain Francoise <[email protected]>
http://people.debian.org/~rfrancoise/
--- End Message ---