]> The Tcpdump Group git mirrors - tcpdump/blobdiff - addrtoname.c
gre: add support for MikroTik Ethernet-over-IP hack.
[tcpdump] / addrtoname.c
index eb3df77ee7ea2ebad9e6591075013ecac3cde691..b60384cb74ca24ed93adb539c036816751c4d5fc 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>
@@ -151,14 +148,15 @@ win32_gethostbyaddr(const char *addr, int len, int type)
        static struct hostent host;
        static char hostbuf[NI_MAXHOST];
        char hname[NI_MAXHOST];
-       struct sockaddr_in6 addr6;
 
        host.h_name = hostbuf;
        switch (type) {
        case AF_INET:
                return gethostbyaddr(addr, len, type);
                break;
-       case AF_INET6:
+#ifdef AF_INET6
+       case AF_INET6: {
+               struct sockaddr_in6 addr6;
                memset(&addr6, 0, sizeof(addr6));
                addr6.sin6_family = AF_INET6;
                memcpy(&addr6.sin6_addr, addr, len);
@@ -170,6 +168,8 @@ win32_gethostbyaddr(const char *addr, int len, int type)
                        return &host;
                }
                break;
+       }
+#endif /* AF_INET6 */
        default:
                return NULL;
        }
@@ -361,6 +361,7 @@ ip6addr_string(netdissect_options *ndo, const u_char *ap)
        /*
         * Do not print names if -n was given.
         */
+#ifdef AF_INET6
        if (!ndo->ndo_nflag) {
 #ifdef HAVE_CASPER
                if (capdns != NULL) {
@@ -386,6 +387,7 @@ ip6addr_string(netdissect_options *ndo, const u_char *ap)
                        return (p->name);
                }
        }
+#endif /* AF_INET6 */
        cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
        p->name = strdup(cp);
        if (p->name == NULL)
@@ -529,8 +531,7 @@ lookup_nsap(netdissect_options *ndo, const u_char *nsap,
                k = (ensap[0] << 8) | ensap[1];
                j = (ensap[2] << 8) | ensap[3];
                i = (ensap[4] << 8) | ensap[5];
-       }
-       else
+       } else
                i = j = k = 0;
 
        tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
@@ -1288,7 +1289,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)
@@ -1308,7 +1309,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)