diff options
author | guy <guy> | 2008-07-01 08:02:33 +0000 |
---|---|---|
committer | guy <guy> | 2008-07-01 08:02:33 +0000 |
commit | 34624f128f2e6f937c04317fdd2c0ae6d8883ad5 (patch) | |
tree | df708730b36c2a96e7ee94c7b926d4d5bf4d6e64 /pcap-bpf.c | |
parent | a8e63c60ed4d25d27c890ecab14e1a831dbeb198 (diff) |
When activating a device, return PCAP_ERROR_IFACE_NOT_UP if the device
isn't up, so applications can report that differently from a generic
error (the latter could mean there's a bug somewhere in libpcap).
When capturing on a device without mmap on Linux, ignore ENETDOWN, so
that we can continue to capture traffic if the interface goes down and
comes back up again; comments in the kernel indicate that we'll just
block waiting for packets if we try to receive from a socket that
delivered ENETDOWN, and, if we're using a memory-mapped buffer, we won't
even get notified of "network down" events.
Diffstat (limited to 'pcap-bpf.c')
-rw-r--r-- | pcap-bpf.c | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.110 2008-04-14 20:40:58 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.111 2008-07-01 08:02:33 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -413,11 +413,23 @@ pcap_can_set_rfmon_bpf(pcap_t *p) */ (void)strncpy(ifr.ifr_name, p->opt.source, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "BIOCSETIF: %s: %s", - p->opt.source, pcap_strerror(errno)); - close(fd); - return (PCAP_ERROR); + if (errno == ENETDOWN) { + /* + * Return a "network down" indication, so that + * the application can report that rather than + * saying we had a mysterious failure and + * suggest that they report a problem to the + * libpcap developers. + */ + close(fd); + return (PCAP_ERROR_IFACE_NOT_UP); + } else { + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "BIOCSETIF: %s: %s", + p->opt.source, pcap_strerror(errno)); + close(fd); + return (PCAP_ERROR); + } } /* @@ -1016,6 +1028,15 @@ check_setif_failure(pcap_t *p, int error) */ strcpy(p->errbuf, ""); return (PCAP_ERROR_NO_SUCH_DEVICE); + } else if (errno == ENETDOWN) { + /* + * Return a "network down" indication, so that + * the application can report that rather than + * saying we had a mysterious failure and + * suggest that they report a problem to the + * libpcap developers. + */ + return (PCAP_ERROR_IFACE_NOT_UP); } else { /* * Some other error; fill in the error string, and |