dect
/
libpcap
Archived
13
0
Fork 0

The pcap_activate() man page says:

If PCAP_WARNING_PROMISC_NOTSUP, PCAP_ERROR_NO_SUCH_DEVICE, or
	PCAP_ERROR_PERM_DENIED is returned, pcap_geterr() or
	pcap_perror() may be called with p as an argument to fetch or
	display an message giving additional details about the problem
	that might be useful for debugging the problem if it's
	unexpected.

but we weren't always setting the error string in question.  Do so.

In pcap_open_live(), if the open fails with PCAP_ERROR, include the
device name in the error string, and if it fails with
PCAP_ERROR_NO_SUCH_DEVICE or PCAP_ERROR_PERM_DENIED, include the device
name and both error messages in the error string.
This commit is contained in:
Guy Harris 2009-07-30 20:58:08 -07:00
parent 0101db9e7c
commit efeaba4650
3 changed files with 24 additions and 7 deletions

View File

@ -1283,7 +1283,9 @@ check_setif_failure(pcap_t *p, int error)
* exist. * exist.
*/ */
err = PCAP_ERROR_NO_SUCH_DEVICE; err = PCAP_ERROR_NO_SUCH_DEVICE;
strcpy(p->errbuf, ""); snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"SIOCGIFFLAGS on %s failed: %s",
ifr.ifr_name, pcap_strerror(errno));
} else { } else {
/* /*
* The underlying "enN" device * The underlying "enN" device
@ -1305,7 +1307,9 @@ check_setif_failure(pcap_t *p, int error)
* just report "no such device". * just report "no such device".
*/ */
err = PCAP_ERROR_NO_SUCH_DEVICE; err = PCAP_ERROR_NO_SUCH_DEVICE;
strcpy(p->errbuf, ""); snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"socket() failed: %s",
pcap_strerror(errno));
} }
return (err); return (err);
} }
@ -1313,7 +1317,8 @@ check_setif_failure(pcap_t *p, int error)
/* /*
* No such device. * No such device.
*/ */
strcpy(p->errbuf, ""); snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETIF failed: %s",
pcap_strerror(errno));
return (PCAP_ERROR_NO_SUCH_DEVICE); return (PCAP_ERROR_NO_SUCH_DEVICE);
} else if (errno == ENETDOWN) { } else if (errno == ENETDOWN) {
/* /*
@ -1445,7 +1450,10 @@ pcap_activate_bpf(pcap_t *p)
* exist. * exist.
*/ */
status = PCAP_ERROR_NO_SUCH_DEVICE; status = PCAP_ERROR_NO_SUCH_DEVICE;
strcpy(p->errbuf, ""); snprintf(p->errbuf,
PCAP_ERRBUF_SIZE,
"SIOCGIFFLAGS failed: %s",
pcap_strerror(errno));
} else } else
status = PCAP_ERROR_RFMON_NOTSUP; status = PCAP_ERROR_RFMON_NOTSUP;
close(sockfd); close(sockfd);
@ -1456,7 +1464,10 @@ pcap_activate_bpf(pcap_t *p)
* report "no such device". * report "no such device".
*/ */
status = PCAP_ERROR_NO_SUCH_DEVICE; status = PCAP_ERROR_NO_SUCH_DEVICE;
strcpy(p->errbuf, ""); snprintf(p->errbuf,
PCAP_ERRBUF_SIZE,
"socket() failed: %s",
pcap_strerror(errno));
} }
goto bad; goto bad;
} }

View File

@ -880,6 +880,8 @@ pcap_can_set_rfmon_linux(pcap_t *handle)
} }
if (errno == ENODEV) { if (errno == ENODEV) {
/* The device doesn't even exist. */ /* The device doesn't even exist. */
(void)snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"SIOCGIWMODE failed: %s", pcap_strerror(errno));
close(sock_fd); close(sock_fd);
return PCAP_ERROR_NO_SUCH_DEVICE; return PCAP_ERROR_NO_SUCH_DEVICE;
} }

8
pcap.c
View File

@ -340,9 +340,13 @@ pcap_open_live(const char *source, int snaplen, int promisc, int to_ms, char *er
goto fail; goto fail;
return (p); return (p);
fail: fail:
if (status == PCAP_ERROR || status == PCAP_ERROR_NO_SUCH_DEVICE || if (status == PCAP_ERROR)
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
p->errbuf);
else if(status == PCAP_ERROR_NO_SUCH_DEVICE ||
status == PCAP_ERROR_PERM_DENIED) status == PCAP_ERROR_PERM_DENIED)
strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", source,
pcap_statustostr(status), p->errbuf);
else else
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source, snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
pcap_statustostr(status)); pcap_statustostr(status));