Return more specific errors from pcap_can_set_rfmon(); fix documentation.
Have pcap_can_set_rfmon() return PCAP_ERROR_PERM_DENIED if you don't have permission to check the device and PCAP_ERROR_NO_SUCH_DEVICE if there's no such device, at least on Mac OS X. Other platforms need to be fixed as well. Update the documentatation to reflect that it can return PCAP_ERROR_PERM_DENIED, fix a typo, and speak of capture sources rather than devices.
This commit is contained in:
parent
59b866591a
commit
0a77b1b15f
29
pcap-bpf.c
29
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));
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue