X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/51288332aea19566627aed7a5018cd35367df10d..c909e8a31ffcbb7f1a41bb801392e14f5d20e1fc:/pcap-netmap.c diff --git a/pcap-netmap.c b/pcap-netmap.c index 3c9de68a..ee8d8b3a 100644 --- a/pcap-netmap.c +++ b/pcap-netmap.c @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif #include @@ -188,13 +188,14 @@ static int pcap_netmap_activate(pcap_t *p) { struct pcap_netmap *pn = p->priv; - struct nm_desc *d = nm_open(p->opt.device, NULL, 0, NULL); + struct nm_desc *d; uint32_t if_flags = 0; + d = nm_open(p->opt.device, NULL, 0, NULL); if (d == NULL) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "netmap open: cannot access %s: %s\n", - p->opt.device, pcap_strerror(errno)); + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "netmap open: cannot access %s", + p->opt.device); pcap_cleanup_live_common(p); return (PCAP_ERROR); } @@ -204,6 +205,18 @@ pcap_netmap_activate(pcap_t *p) d->first_rx_ring, d->last_rx_ring); pn->d = d; p->fd = d->fd; + + /* + * 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; + if (p->opt.promisc && !(d->req.nr_ringid & NETMAP_SW_RING)) { pcap_netmap_ioctl(p, SIOCGIFFLAGS, &if_flags); /* fetch flags */ if (!(if_flags & IFF_PPROMISC)) { @@ -244,11 +257,12 @@ pcap_netmap_create(const char *device, char *ebuf, int *is_ours) } /* - * XXX - is there a way to enumerate the netmap devices? + * The "device name" for netmap devices isn't a name for a device, it's + * an expression that indicates how the device should be set up, so + * there's no way to enumerate them. */ int -pcap_netmap_findalldevs(pcap_if_list_t *devlistp, char *err_str) +pcap_netmap_findalldevs(pcap_if_list_t *devlistp _U_, char *err_str _U_) { return 0; } -