diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-06-28 02:29:46 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-06-28 02:30:09 -0700 |
commit | 01dabcda25ed695976e5c844cdd7fc6875a17bf6 (patch) | |
tree | 1942c269617b36aa4dcb03ce42f4cf26da8e599c /fad-glifc.c | |
parent | 71d90a93c5cb7f15e10254d6ee711f1f690b0a9c (diff) |
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.
Diffstat (limited to 'fad-glifc.c')
-rw-r--r-- | fad-glifc.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/fad-glifc.c b/fad-glifc.c index 9107b44e..5830628b 100644 --- a/fad-glifc.c +++ b/fad-glifc.c @@ -75,7 +75,8 @@ struct rtentry; /* declarations in <net/if.h> */ * SIOCGLIFCONF rather than SIOCGIFCONF in order to get IPv6 addresses.) */ int -pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf) +pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf, + int (*check_usable)(const char *)) { pcap_if_t *devlist = NULL; register int fd4, fd6, fd; @@ -165,14 +166,6 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf) for (; ifrp < ifend; ifrp++) { /* - * IPv6 or not? - */ - if (((struct sockaddr *)&ifrp->lifr_addr)->sa_family == AF_INET6) - fd = fd6; - else - fd = fd4; - - /* * Skip entries that begin with "dummy". * XXX - what are these? Is this Linux-specific? * Are there platforms on which we shouldn't do this? @@ -203,6 +196,24 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf) #endif /* + * Can we capture on this device? + */ + if (!(*check_usable)(ifrp->lifr_name)) { + /* + * No. + */ + continue; + } + + /* + * IPv6 or not? + */ + if (((struct sockaddr *)&ifrp->lifr_addr)->sa_family == AF_INET6) + fd = fd6; + else + fd = fd4; + + /* * Get the flags for this interface. */ strncpy(ifrflags.lifr_name, ifrp->lifr_name, |