diff options
author | guy <guy> | 2008-04-09 19:58:02 +0000 |
---|---|---|
committer | guy <guy> | 2008-04-09 19:58:02 +0000 |
commit | 216c64a7ceaa12e96df1c45f90c943d2d958a9cc (patch) | |
tree | b9cb66f808df898f5ffdb0e2d68da5a89f7bd9e3 /pcap-libdlpi.c | |
parent | 745e497e4c79442396fa780f45be0381ea09d002 (diff) | |
download | libpcap-216c64a7ceaa12e96df1c45f90c943d2d958a9cc.tar.gz |
Add an error for "you don't have permission to open that device", as
that often means "sorry, this platform requires you to run as root or to
somehow tweak the system to give you capture privileges", and
applications might want to explain that in a way that does a better job
of letting the user know what they have to do.
Try to return or PCAP_ERROR_PERM_DENIED for open errors, rather than
just returning PCAP_ERROR, so that the application can, if it chooses,
try to explain the error better (as those two errors are the ones that
don't mean "there's probably some obscure OS or libpcap problem", but
mean, instead, "you made an error" or "you need to get permission to
capture").
Check for monitor mode *after* checking whether the device exists in the
first place; a non-existent device doesn't support monitor mode, but
that's because it doesn't, well, exist, and the latter would be a more
meaningful error.
Have pcap_open_live() supply an error message for return values other
than PCAP_ERROR, PCAP_ERROR_NO_SUCH_DEVICE, and PCAP_ERROR_PERM_DENIED -
those all supply error strings (PCAP_ERROR because it's for various OS
problems that might require debugging, and the other two because there
might be multiple causes).
Diffstat (limited to 'pcap-libdlpi.c')
-rw-r--r-- | pcap-libdlpi.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/pcap-libdlpi.c b/pcap-libdlpi.c index d1df5ba2..90029847 100644 --- a/pcap-libdlpi.c +++ b/pcap-libdlpi.c @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-libdlpi.c,v 1.4 2008-04-04 19:37:45 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-libdlpi.c,v 1.5 2008-04-09 19:58:02 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -102,13 +102,7 @@ pcap_activate_libdlpi(pcap_t *p) int retv; dlpi_handle_t dh; dlpi_info_t dlinfo; - - if (p->opt.rfmon) { - /* - * No monitor mode on any platforms that support DLPI. - */ - return (PCAP_ERROR_RFMON_NOTSUP); - } + int err = PCAP_ERROR; p->fd = -1; /* indicate that it hasn't been opened yet */ @@ -119,11 +113,25 @@ pcap_activate_libdlpi(pcap_t *p) */ retv = dlpi_open(p->opt.source, &dh, DLPI_RAW|DLPI_PASSIVE); if (retv != DLPI_SUCCESS) { - pcap_libdlpi_err(p->opt.source, "dlpi_open", retv, p->errbuf); - goto bad; + if (retv == DLPI_ELINKNAMEINVAL || retv == DLPI_ENOLINK) + err = PCAP_ERROR_NO_SUCH_DEVICE; + else if (retv == DLPI_SYSERR && errno == EACCES) + err = PCAP_ERROR_PERM_DENIED; + pcap_libdlpi_err(p->opt.source, "dlpi_open", retv, + p->errbuf); + return (err); } p->dlpi_hd = dh; + if (p->opt.rfmon) { + /* + * This device exists, but we don't support monitor mode + * any platforms that support DLPI. + */ + err = PCAP_ERROR_RFMON_NOTSUP; + goto bad; + } + /* Bind with DLPI_ANY_SAP. */ if ((retv = dlpi_bind(p->dlpi_hd, DLPI_ANY_SAP, 0)) != DLPI_SUCCESS) { pcap_libdlpi_err(p->opt.source, "dlpi_bind", retv, p->errbuf); @@ -211,7 +219,7 @@ bad: if (p->dlt_list != NULL) free(p->dlt_list); dlpi_close(p->dlpi_hd); - return (PCAP_ERROR); + return (err); } /* |