]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap-netmap.c
ATM: Simplify protocol and message type handling.
[libpcap] / pcap-netmap.c
index 573f4c3112577bb5fc542789b5812718ad596022..56a6bc418086d8aad8d70615ce146ed527d2395d 100644 (file)
@@ -24,9 +24,7 @@
  * SUCH DAMAGE.
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <poll.h>
 #include <errno.h>
@@ -35,6 +33,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/ioctl.h>
 
 #define NETMAP_WITH_LIBS
 #include <net/netmap_user.h>
@@ -133,15 +132,19 @@ pcap_netmap_ioctl(pcap_t *p, u_long what, uint32_t *if_flags)
        struct ifreq ifr;
        int error, fd = d->fd;
 
-#ifdef linux
+#ifdef __linux__
        fd = socket(AF_INET, SOCK_DGRAM, 0);
        if (fd < 0) {
                fprintf(stderr, "Error: cannot get device control socket.\n");
                return -1;
        }
-#endif /* linux */
+#endif /* __linux__ */
        bzero(&ifr, sizeof(ifr));
-       strncpy(ifr.ifr_name, d->req.nr_name, sizeof(ifr.ifr_name));
+       /*
+        * ifreq.ifr_name and nmreq.nr_name have the same size and both
+        * contain a NUL-terminated string.
+        */
+       (void)pcapint_strlcpy(ifr.ifr_name, d->req.nr_name, sizeof(ifr.ifr_name));
        switch (what) {
        case SIOCSIFFLAGS:
                /*
@@ -194,9 +197,9 @@ pcap_netmap_ioctl(pcap_t *p, u_long what, uint32_t *if_flags)
 #endif /* __FreeBSD__ */
                }
        }
-#ifdef linux
+#ifdef __linux__
        close(fd);
-#endif /* linux */
+#endif /* __linux__ */
        return error ? -1 : 0;
 }
 
@@ -237,7 +240,7 @@ pcap_netmap_activate(pcap_t *p)
        }
 #if 0
        fprintf(stderr, "%s device %s priv %p fd %d ports %d..%d\n",
-           __FUNCTION__, p->opt.device, d, d->fd,
+           __func__, p->opt.device, d, d->fd,
            d->first_rx_ring, d->last_rx_ring);
 #endif
        pn->d = d;