aboutsummaryrefslogtreecommitdiff
path: root/contrib/libpcap/pcap-libdlpi.c
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2018-05-28 08:12:18 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2018-05-28 08:12:18 +0000
commitb00ab7548b418624b6719ab8a2e8aaeade767a70 (patch)
treea300b8fb3f3e9cbbd48c47fde148dcb40453e7de /contrib/libpcap/pcap-libdlpi.c
parent7e3d9013f2ff9291970339df66a18ad9343ed433 (diff)
parentd109bf9e4b609b5a0626b433e56db4a47dc530bb (diff)
downloadsrc-b00ab7548b418624b6719ab8a2e8aaeade767a70.tar.gz
src-b00ab7548b418624b6719ab8a2e8aaeade767a70.zip
MFV r333789: libpcap 1.9.0 (pre-release)
MFC after: 1 month Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/head/; revision=334277
Diffstat (limited to 'contrib/libpcap/pcap-libdlpi.c')
-rw-r--r--contrib/libpcap/pcap-libdlpi.c72
1 files changed, 64 insertions, 8 deletions
diff --git a/contrib/libpcap/pcap-libdlpi.c b/contrib/libpcap/pcap-libdlpi.c
index 625f1e0a31ed..a0d16693f6c2 100644
--- a/contrib/libpcap/pcap-libdlpi.c
+++ b/contrib/libpcap/pcap-libdlpi.c
@@ -25,7 +25,7 @@
*/
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <sys/types.h>
@@ -137,6 +137,17 @@ pcap_activate_libdlpi(pcap_t *p)
goto bad;
}
+ /*
+ * Turn a negative snapshot value (invalid), a snapshot value of
+ * 0 (unspecified), or a value bigger than the normal maximum
+ * value, into the maximum allowed value.
+ *
+ * If some application really *needs* a bigger snapshot
+ * length, we should just increase MAXIMUM_SNAPLEN.
+ */
+ if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
+ p->snapshot = MAXIMUM_SNAPLEN;
+
/* Enable promiscuous mode. */
if (p->opt.promisc) {
retv = dlpromiscon(p, DL_PROMISC_PHYS);
@@ -209,8 +220,8 @@ pcap_activate_libdlpi(pcap_t *p)
*/
if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
status = PCAP_ERROR;
- pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "FLUSHR: %s",
- pcap_strerror(errno));
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "FLUSHR");
goto bad;
}
@@ -276,13 +287,36 @@ is_dlpi_interface(const char *name _U_)
return (1);
}
+static int
+get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
+{
+ /*
+ * Nothing we can do other than mark loopback devices as "the
+ * connected/disconnected status doesn't apply".
+ *
+ * XXX - on Solaris, can we do what the dladm command does,
+ * i.e. get a connected/disconnected indication from a kstat?
+ * (Note that you can also get the link speed, and possibly
+ * other information, from a kstat as well.)
+ */
+ if (*flags & PCAP_IF_LOOPBACK) {
+ /*
+ * Loopback devices aren't wireless, and "connected"/
+ * "disconnected" doesn't apply to them.
+ */
+ *flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE;
+ return (0);
+ }
+ return (0);
+}
+
/*
* In Solaris, the "standard" mechanism" i.e SIOCGLIFCONF will only find
* network links that are plumbed and are up. dlpi_walk(3DLPI) will find
* additional network links present in the system.
*/
int
-pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
+pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
{
int retv = 0;
@@ -293,23 +327,36 @@ pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
/*
* Get the list of regular interfaces first.
*/
- if (pcap_findalldevs_interfaces(alldevsp, errbuf, is_dlpi_interface) == -1)
+ if (pcap_findalldevs_interfaces(devlistp, errbuf,
+ is_dlpi_interface, get_if_flags) == -1)
return (-1); /* failure */
/* dlpi_walk() for loopback will be added here. */
+ /*
+ * Find all DLPI devices in the current zone.
+ *
+ * XXX - will pcap_findalldevs_interfaces() find any devices
+ * outside the current zone? If not, the only reason to call
+ * it would be to get the interface addresses.
+ */
dlpi_walk(list_interfaces, &lw, 0);
if (lw.lw_err != 0) {
- pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "dlpi_walk: %s", pcap_strerror(lw.lw_err));
+ pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
+ lw.lw_err, "dlpi_walk");
retv = -1;
goto done;
}
/* Add linkname if it does not exist on the list. */
for (entry = lw.lw_list; entry != NULL; entry = entry->lnl_next) {
- if (pcap_add_if(alldevsp, entry->linkname, 0, NULL, errbuf) < 0)
+ /*
+ * If it isn't already in the list of devices, try to
+ * add it.
+ */
+ if (find_or_add_dev(devlistp, entry->linkname, 0, get_if_flags,
+ NULL, errbuf) == NULL)
retv = -1;
}
done:
@@ -437,3 +484,12 @@ pcap_create_interface(const char *device _U_, char *ebuf)
p->activate_op = pcap_activate_libdlpi;
return (p);
}
+
+/*
+ * Libpcap version string.
+ */
+const char *
+pcap_lib_version(void)
+{
+ return (PCAP_VERSION_STRING);
+}