From 01dabcda25ed695976e5c844cdd7fc6875a17bf6 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 28 Jun 2016 02:29:46 -0700 Subject: Let the platform decide how to check capturable interfaces. (Git's annoying policy of expecting a short one-line description of every change means that the first line isn't very explanatory.) Make pcap_findalldevs_interfaces() take as an argument a function that's used to check whether an interface can be captured on or not, rather than doing the check by trying to open the device for capturing. This lets pcap_findalldevs() find interfaces even if you don't have permission to capture on them; that way, instead of users saying "why isn't {tcpdump -D, tshark -D, dumpcap -D, Wireshark, etc.} showing me any interfaces?", they'll say "why am I getting a 'you don't have permissions' error when I try to capture on this interface?", which is a better description of the underlying problem. On some platforms, it also avoids a bunch of extra work when getting a list of interfaces. --- pcap-snit.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'pcap-snit.c') diff --git a/pcap-snit.c b/pcap-snit.c index 3a50007e..a1f5e035 100644 --- a/pcap-snit.c +++ b/pcap-snit.c @@ -354,6 +354,11 @@ pcap_activate_snit(pcap_t *p) si.ic_len = sizeof(ifr); si.ic_dp = (char *)𝔦 if (ioctl(fd, I_STR, (char *)&si) < 0) { + /* + * XXX - is there an error that means "no such device"? + * Is there one that means "that device doesn't support + * STREAMS NIT"? + */ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "NIOCBIND: %s: %s", ifr.ifr_name, pcap_strerror(errno)); goto bad; @@ -438,8 +443,18 @@ pcap_create_interface(const char *device, char *ebuf) return (p); } +/* + * XXX - there's probably a NIOCBIND error that means "that device + * doesn't support NIT"; if so, we should try an NIOCBIND and use that. + */ +static int +can_be_bound(const char *name _U_) +{ + return (1); +} + int pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf) { - return (pcap_findalldevs_interfaces(alldevsp, errbuf)); + return (pcap_findalldevs_interfaces(alldevsp, errbuf, can_be_bound)); } -- cgit v1.2.3