]> The Tcpdump Group git mirrors - tcpdump/blobdiff - addrtoname.c
Makefile.in: don't remove configure and config.h.in in make distclean.
[tcpdump] / addrtoname.c
index 33b93784b231da3e8e9d36721a646222ece93fce..914665c2315a2d8b8fed7bdf1b6c2a4edb8692ab 100644 (file)
 
 #include "netdissect-stdinc.h"
 
-#ifdef _WIN32
-  /*
-   * We have our own ether_ntohost(), reading from the system's
-   * Ethernet address file.
-   */
-  #include "missing/win_ether_ntohost.h"
-#else
-  #ifdef USE_ETHER_NTOHOST
-    #if defined(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
-      /*
-       * OK, just include <net/ethernet.h>.
-       */
-      #include <net/ethernet.h>
-    #elif defined(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
-      /*
-       * OK, just include <netinet/ether.h>
-       */
-      #include <netinet/ether.h>
-    #elif defined(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
-      /*
-       * OK, just include <sys/ethernet.h>
-       */
-      #include <sys/ethernet.h>
-    #elif defined(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
-      /*
-       * OK, just include <arpa/inet.h>
-       */
-      #include <arpa/inet.h>
-    #elif defined(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
-      /*
-       * OK, include <netinet/if_ether.h>, after all the other stuff we
-       * need to include or define for its benefit.
-       */
+#ifdef USE_ETHER_NTOHOST
+  #if defined(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
+    /*
+     * OK, just include <net/ethernet.h>.
+     */
+    #include <net/ethernet.h>
+  #elif defined(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
+    /*
+     * OK, just include <netinet/ether.h>
+     */
+    #include <netinet/ether.h>
+  #elif defined(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
+    /*
+     * OK, just include <sys/ethernet.h>
+     */
+    #include <sys/ethernet.h>
+  #elif defined(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
+    /*
+     * OK, just include <arpa/inet.h>
+     */
+    #include <arpa/inet.h>
+  #elif defined(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
+    /*
+     * OK, include <netinet/if_ether.h>, after all the other stuff we
+     * need to include or define for its benefit.
+     */
+    #define NEED_NETINET_IF_ETHER_H
+  #else
+    /*
+     * We'll have to declare it ourselves.
+     * If <netinet/if_ether.h> defines struct ether_addr, include
+     * it.  Otherwise, define it ourselves.
+     */
+    #ifdef HAVE_STRUCT_ETHER_ADDR
       #define NEED_NETINET_IF_ETHER_H
-    #else
-      /*
-       * We'll have to declare it ourselves.
-       * If <netinet/if_ether.h> defines struct ether_addr, include
-       * it.  Otherwise, define it ourselves.
-       */
-      #ifdef HAVE_STRUCT_ETHER_ADDR
-        #define NEED_NETINET_IF_ETHER_H
-      #else /* HAVE_STRUCT_ETHER_ADDR */
+    #else /* HAVE_STRUCT_ETHER_ADDR */
        struct ether_addr {
+               /* Beware FreeBSD calls this "octet". */
                unsigned char ether_addr_octet[MAC_ADDR_LEN];
        };
-      #endif /* HAVE_STRUCT_ETHER_ADDR */
-    #endif /* what declares ether_ntohost() */
-
-    #ifdef NEED_NETINET_IF_ETHER_H
-      #include <net/if.h>      /* Needed on some platforms */
-      #include <netinet/in.h>  /* Needed on some platforms */
-      #include <netinet/if_ether.h>
-    #endif /* NEED_NETINET_IF_ETHER_H */
-
-    #ifndef HAVE_DECL_ETHER_NTOHOST
-      /*
-       * No header declares it, so declare it ourselves.
-       */
-      extern int ether_ntohost(char *, const struct ether_addr *);
-    #endif /* !defined(HAVE_DECL_ETHER_NTOHOST) */
-  #endif /* USE_ETHER_NTOHOST */
-#endif /* _WIN32 */
+    #endif /* HAVE_STRUCT_ETHER_ADDR */
+  #endif /* what declares ether_ntohost() */
+
+  #ifdef NEED_NETINET_IF_ETHER_H
+    /*
+     * Include diag-control.h before <net/if.h>, which too defines a macro
+     * named ND_UNREACHABLE.
+     */
+    #include "diag-control.h"
+    #include <net/if.h>                /* Needed on some platforms */
+    #include <netinet/in.h>    /* Needed on some platforms */
+    #include <netinet/if_ether.h>
+  #endif /* NEED_NETINET_IF_ETHER_H */
+
+  #ifndef HAVE_DECL_ETHER_NTOHOST
+    /*
+     * No header declares it, so declare it ourselves.
+     */
+    extern int ether_ntohost(char *, const struct ether_addr *);
+  #endif /* !defined(HAVE_DECL_ETHER_NTOHOST) */
+#endif /* USE_ETHER_NTOHOST */
 
 #include <pcap.h>
 #include <pcap-namedb.h>
@@ -253,7 +251,7 @@ intoa(uint32_t addr)
 static uint32_t f_netmask;
 static uint32_t f_localnet;
 #ifdef HAVE_CASPER
-extern cap_channel_t *capdns;
+cap_channel_t *capdns;
 #endif
 
 /*
@@ -601,8 +599,15 @@ etheraddr_string(netdissect_options *ndo, const uint8_t *ep)
 #ifdef USE_ETHER_NTOHOST
        if (!ndo->ndo_nflag) {
                char buf2[BUFSIZE];
+               /*
+                * This is a non-const copy of ep for ether_ntohost(), which
+                * has its second argument non-const in OpenBSD. Also saves a
+                * type cast.
+                */
+               struct ether_addr ea;
 
-               if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) {
+               memcpy (&ea, ep, MAC_ADDR_LEN);
+               if (ether_ntohost(buf2, &ea) == 0) {
                        tp->e_name = strdup(buf2);
                        if (tp->e_name == NULL)
                                (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
@@ -977,7 +982,10 @@ init_etherarray(netdissect_options *ndo)
                /*
                 * Use YP/NIS version of name if available.
                 */
-               if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) {
+               /* Same workaround as in etheraddr_string(). */
+               struct ether_addr ea;
+               memcpy (&ea, el->addr, MAC_ADDR_LEN);
+               if (ether_ntohost(name, &ea) == 0) {
                        tp->e_name = strdup(name);
                        if (tp->e_name == NULL)
                                (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
@@ -1277,7 +1285,7 @@ newhnamemem(netdissect_options *ndo)
        static struct hnamemem *ptr = NULL;
        static u_int num = 0;
 
-       if (num  <= 0) {
+       if (num  == 0) {
                num = 64;
                ptr = (struct hnamemem *)calloc(num, sizeof (*ptr));
                if (ptr == NULL)
@@ -1297,7 +1305,7 @@ newh6namemem(netdissect_options *ndo)
        static struct h6namemem *ptr = NULL;
        static u_int num = 0;
 
-       if (num  <= 0) {
+       if (num  == 0) {
                num = 64;
                ptr = (struct h6namemem *)calloc(num, sizeof (*ptr));
                if (ptr == NULL)