]> The Tcpdump Group git mirrors - libpcap/commitdiff
For now, move the UN*X pcap_lookupnet() to pcap.c.
authorGuy Harris <[email protected]>
Thu, 7 Sep 2017 23:52:18 +0000 (16:52 -0700)
committerGuy Harris <[email protected]>
Thu, 7 Sep 2017 23:52:18 +0000 (16:52 -0700)
Eventually, we want an API to return a list of attributes for a device
(like the options for a pcapng Interface Description Block), and we
could use that in pcap_lookupnet(), so the platform dependencies are
pushed down to the list-of-attributes API.

CMakeLists.txt
INSTALL.txt
Makefile.in
inet.c [deleted file]
pcap.c

index 88d8fc3bde3efb4289c460348454bc37a4bc25e5..32dc198cb73a2236ddc4c01563423f34ae229e1f 100644 (file)
@@ -225,12 +225,6 @@ if( WIN32 )
 else()
     #
     # UN*X.
-    #
-    # We use the pcap_lookupdev() and pcap_lookupnet() from
-    # inet.c.
-    #
-    set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} inet.c)
-
     #
     # Figure out what type of packet capture mechanism we have.
     #
index d904ef703b14d99c40fe897447b06ff54a9b5219..74aa01d3f574156f2daf035dd18cbae4cd47ba59 100644 (file)
@@ -315,7 +315,6 @@ gencode.c   - BPF code generation routines
 gencode.h      - BPF code generation definitions
 grammar.y      - filter string grammar
 ieee80211.h    - 802.11 definitions
-inet.c         - network routines
 install-sh     - BSD style install script
 lbl/os-*.h     - OS-dependent defines and prototypes
 llc.h          - 802.2 LLC SAP definitions
index d75336838f782d3f2202537444f8af0dec9ad7ae..66f7de35d767969de97c7403b6ad582d0fac62ed 100644 (file)
@@ -86,7 +86,7 @@ YACC = @YACC@
 PSRC = pcap-@[email protected] @USB_SRC@ @BT_SRC@ @BT_MONITOR_SRC@ @NETFILTER_SRC@ @DBUS_SRC@ @NETMAP_SRC@ @RDMA_SRC@
 FSRC =  @V_FINDALLDEVS@
 SSRC =  @SSRC@
-CSRC = pcap.c inet.c gencode.c optimize.c nametoaddr.c \
+CSRC = pcap.c gencode.c optimize.c nametoaddr.c \
        etherent.c savefile.c sf-pcap.c sf-pcap-ng.c pcap-common.c \
        bpf_image.c bpf_dump.c
 GENSRC = scanner.c grammar.c bpf_filter.c version.c
diff --git a/inet.c b/inet.c
deleted file mode 100644 (file)
index cb9ca4f..0000000
--- a/inet.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
-/*
- * Copyright (c) 1994, 1995, 1996, 1997, 1998
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the Computer Systems
- *     Engineering Group at Lawrence Berkeley Laboratory.
- * 4. Neither the name of the University nor of the Laboratory may be used
- *    to endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/param.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#ifdef HAVE_SYS_SOCKIO_H
-#include <sys/sockio.h>
-#endif
-
-struct mbuf;           /* Squelch compiler warnings on some platforms for */
-struct rtentry;                /* declarations in <net/if.h> */
-#include <net/if.h>
-#include <netinet/in.h>
-
-#include <errno.h>
-#include <memory.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "pcap-int.h"
-
-#ifdef HAVE_OS_PROTO_H
-#include "os-proto.h"
-#endif
-
-/*
- * UN*X.
- */
-/*
- * We don't just fetch the entire list of devices, search for the
- * particular device, and use its first IPv4 address, as that's too
- * much work to get just one device's netmask.
- */
-int
-pcap_lookupnet(device, netp, maskp, errbuf)
-       register const char *device;
-       register bpf_u_int32 *netp, *maskp;
-       register char *errbuf;
-{
-       register int fd;
-       register struct sockaddr_in *sin4;
-       struct ifreq ifr;
-
-       /*
-        * The pseudo-device "any" listens on all interfaces and therefore
-        * has the network address and -mask "0.0.0.0" therefore catching
-        * all traffic. Using NULL for the interface is the same as "any".
-        */
-       if (!device || strcmp(device, "any") == 0
-#ifdef HAVE_DAG_API
-           || strstr(device, "dag") != NULL
-#endif
-#ifdef HAVE_SEPTEL_API
-           || strstr(device, "septel") != NULL
-#endif
-#ifdef PCAP_SUPPORT_BT
-           || strstr(device, "bluetooth") != NULL
-#endif
-#ifdef PCAP_SUPPORT_USB
-           || strstr(device, "usbmon") != NULL
-#endif
-#ifdef HAVE_SNF_API
-           || strstr(device, "snf") != NULL
-#endif
-#ifdef PCAP_SUPPORT_NETMAP
-           || strncmp(device, "netmap:", 7) == 0
-           || strncmp(device, "vale", 4) == 0
-#endif
-           ) {
-               *netp = *maskp = 0;
-               return 0;
-       }
-
-       fd = socket(AF_INET, SOCK_DGRAM, 0);
-       if (fd < 0) {
-               (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
-                   pcap_strerror(errno));
-               return (-1);
-       }
-       memset(&ifr, 0, sizeof(ifr));
-#ifdef linux
-       /* XXX Work around Linux kernel bug */
-       ifr.ifr_addr.sa_family = AF_INET;
-#endif
-       (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
-       if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
-               if (errno == EADDRNOTAVAIL) {
-                       (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
-                           "%s: no IPv4 address assigned", device);
-               } else {
-                       (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
-                           "SIOCGIFADDR: %s: %s",
-                           device, pcap_strerror(errno));
-               }
-               (void)close(fd);
-               return (-1);
-       }
-       sin4 = (struct sockaddr_in *)&ifr.ifr_addr;
-       *netp = sin4->sin_addr.s_addr;
-       memset(&ifr, 0, sizeof(ifr));
-#ifdef linux
-       /* XXX Work around Linux kernel bug */
-       ifr.ifr_addr.sa_family = AF_INET;
-#endif
-       (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
-       if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
-               (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
-                   "SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));
-               (void)close(fd);
-               return (-1);
-       }
-       (void)close(fd);
-       *maskp = sin4->sin_addr.s_addr;
-       if (*maskp == 0) {
-               if (IN_CLASSA(*netp))
-                       *maskp = IN_CLASSA_NET;
-               else if (IN_CLASSB(*netp))
-                       *maskp = IN_CLASSB_NET;
-               else if (IN_CLASSC(*netp))
-                       *maskp = IN_CLASSC_NET;
-               else {
-                       (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
-                           "inet class for 0x%x unknown", *netp);
-                       return (-1);
-               }
-       }
-       *netp &= *maskp;
-       return (0);
-}
diff --git a/pcap.c b/pcap.c
index 54296e30b5dc2eb1de02fb2264f56a5394c1d28f..8de39a6b8a692c4088ab51d7ad47c113fa8f6f50 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -1160,6 +1160,111 @@ pcap_lookupdev(errbuf)
        pcap_freealldevs(alldevs);
        return (ret);
 }
+
+/*
+ * We don't just fetch the entire list of devices, search for the
+ * particular device, and use its first IPv4 address, as that's too
+ * much work to get just one device's netmask.
+ *
+ * If we had an API to get attributes for a given device, we could
+ * use that.
+ */
+int
+pcap_lookupnet(device, netp, maskp, errbuf)
+       register const char *device;
+       register bpf_u_int32 *netp, *maskp;
+       register char *errbuf;
+{
+       register int fd;
+       register struct sockaddr_in *sin4;
+       struct ifreq ifr;
+
+       /*
+        * The pseudo-device "any" listens on all interfaces and therefore
+        * has the network address and -mask "0.0.0.0" therefore catching
+        * all traffic. Using NULL for the interface is the same as "any".
+        */
+       if (!device || strcmp(device, "any") == 0
+#ifdef HAVE_DAG_API
+           || strstr(device, "dag") != NULL
+#endif
+#ifdef HAVE_SEPTEL_API
+           || strstr(device, "septel") != NULL
+#endif
+#ifdef PCAP_SUPPORT_BT
+           || strstr(device, "bluetooth") != NULL
+#endif
+#ifdef PCAP_SUPPORT_USB
+           || strstr(device, "usbmon") != NULL
+#endif
+#ifdef HAVE_SNF_API
+           || strstr(device, "snf") != NULL
+#endif
+#ifdef PCAP_SUPPORT_NETMAP
+           || strncmp(device, "netmap:", 7) == 0
+           || strncmp(device, "vale", 4) == 0
+#endif
+           ) {
+               *netp = *maskp = 0;
+               return 0;
+       }
+
+       fd = socket(AF_INET, SOCK_DGRAM, 0);
+       if (fd < 0) {
+               (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
+                   pcap_strerror(errno));
+               return (-1);
+       }
+       memset(&ifr, 0, sizeof(ifr));
+#ifdef linux
+       /* XXX Work around Linux kernel bug */
+       ifr.ifr_addr.sa_family = AF_INET;
+#endif
+       (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+       if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
+               if (errno == EADDRNOTAVAIL) {
+                       (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                           "%s: no IPv4 address assigned", device);
+               } else {
+                       (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                           "SIOCGIFADDR: %s: %s",
+                           device, pcap_strerror(errno));
+               }
+               (void)close(fd);
+               return (-1);
+       }
+       sin4 = (struct sockaddr_in *)&ifr.ifr_addr;
+       *netp = sin4->sin_addr.s_addr;
+       memset(&ifr, 0, sizeof(ifr));
+#ifdef linux
+       /* XXX Work around Linux kernel bug */
+       ifr.ifr_addr.sa_family = AF_INET;
+#endif
+       (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+       if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
+               (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                   "SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));
+               (void)close(fd);
+               return (-1);
+       }
+       (void)close(fd);
+       *maskp = sin4->sin_addr.s_addr;
+       if (*maskp == 0) {
+               if (IN_CLASSA(*netp))
+                       *maskp = IN_CLASSA_NET;
+               else if (IN_CLASSB(*netp))
+                       *maskp = IN_CLASSB_NET;
+               else if (IN_CLASSC(*netp))
+                       *maskp = IN_CLASSC_NET;
+               else {
+                       (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
+                           "inet class for 0x%x unknown", *netp);
+                       return (-1);
+               }
+       }
+       *netp &= *maskp;
+       return (0);
+}
 #endif
 
 #ifdef HAVE_REMOTE