diff --git a/pcap-bpf.c b/pcap-bpf.c index b4482e9..1d2fe17 100644 --- a/pcap-bpf.c +++ b/pcap-bpf.c @@ -672,15 +672,35 @@ pcap_can_set_rfmon_bpf(pcap_t *p) * First, open a BPF device. */ fd = bpf_open(p); - if (fd < 0) - return (fd); + if (fd < 0) { + if (errno == EACCES) { + /* + * Sorry, you don't have permission to do capturing. + */ + return (PCAP_ERROR_PERM_DENIED); + } else { + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "Can't open BPF device for %s: %s", + p->opt.source, pcap_strerror(errno)); + return (PCAP_ERROR); + } + } /* * Now bind to the device. */ (void)strncpy(ifr.ifr_name, p->opt.source, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) { - if (errno == ENETDOWN) { + switch (errno) { + + case ENXIO: + /* + * There's no such device. + */ + close(fd); + return (PCAP_ERROR_NO_SUCH_DEVICE); + + case ENETDOWN: /* * Return a "network down" indication, so that * the application can report that rather than @@ -690,7 +710,8 @@ pcap_can_set_rfmon_bpf(pcap_t *p) */ close(fd); return (PCAP_ERROR_IFACE_NOT_UP); - } else { + + default: snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s", p->opt.source, pcap_strerror(errno)); diff --git a/pcap_can_set_rfmon.3pcap b/pcap_can_set_rfmon.3pcap index 4c85e23..b786694 100644 --- a/pcap_can_set_rfmon.3pcap +++ b/pcap_can_set_rfmon.3pcap @@ -37,11 +37,15 @@ int pcap_can_set_rfmon(pcap_t *p); checks whether monitor mode could be set on a capture handle when the handle is activated. .SH RETURN VALUE -.B pcap_set_rfmon() +.B pcap_can_set_rfmon() returns 0 if monitor mode could not be set, 1 if monitor mode could be set, .B PCAP_ERROR_NO_SUCH_DEVICE -if the device specified when the handle was created doesn't exist, +if the capture source specified when the handle was created doesn't +exist, +.B PCAP_ERROR_PERM_DENIED +if the process doesn't have permission to check whether monitor mode +could be supported, .B PCAP_ERROR_ACTIVATED if called on a capture handle that has been activated, or .B PCAP_ERROR