]> The Tcpdump Group git mirrors - libpcap/commitdiff
Clean up the ether_hostton() stuff.
authorGuy Harris <[email protected]>
Tue, 19 Sep 2017 21:55:13 +0000 (14:55 -0700)
committerGuy Harris <[email protected]>
Tue, 19 Sep 2017 21:55:13 +0000 (14:55 -0700)
On platforms where the OS's ether_hostton man page says "include this",
include that.  However, that doesn't always declare it, so still check
whether it really declares ether_hostton().

Just use AC_CHECK_DECL() to do the checks - that fails either if the
headers in question don't exists or if they exist buf don't end up
declaring ether_hostton().

Check these in CMake as well.

CMakeLists.txt
cmakeconfig.h.in
config.h.in
configure
configure.ac
nametoaddr.c

index a9a3490fa7e06826af35c55a829913d99d837010..8b5497a5c3b5160ea726dda1c9a3f83bd248d796 100644 (file)
@@ -195,6 +195,122 @@ set(CMAKE_EXTRA_INCLUDE_FILES unistd.h)
 #
 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN)
 
+#
+# You are in a twisty little maze of UN*Xes, all different.
+# Some might not have ether_hostton().
+# Some might have it and declare it in <net/ethernet.h>.
+# Some might have it and declare it in <netinet/ether.h>
+# Some might have it and declare it in <sys/ethernet.h>.
+# Some might have it and declare it in <arpa/inet.h>.
+# Some might have it and declare it in <netinet/if_ether.h>.
+# Some might have it and not declare it in any header file.
+#
+# Before you is a C compiler.
+#
+include(CheckSymbolExists)
+check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
+if(HAVE_ETHER_HOSTTON)
+    #
+    # OK, we have ether_hostton().  Is it declared in <net/ethernet.h>?
+    #
+    # This test fails if we don't have <net/ethernet.h> or if we do
+    # but it doesn't declare ether_hostton().
+    #
+    check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
+    if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
+        #
+        # Yes - we have it declared.
+        #
+        set(HAVE_DECL_ETHER_HOSTTON TRUE)
+    endif()
+    #
+    # Did that succeed?
+    #
+    if(NOT HAVE_DECL_ETHER_HOSTTON)
+        #
+        # No - how about <netinet/ether.h>, as on Linux?
+        #
+        # This test fails if we don't have <netinet/ether.h>
+        # or if we do but it doesn't declare ether_hostton().
+        #
+        check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
+        if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
+            #
+            # Yes - we have it declared.
+            #
+            set(HAVE_DECL_ETHER_HOSTTON TRUE)
+        endif()
+    endif()
+    #
+    # Did that succeed?
+    #
+    if(NOT HAVE_DECL_ETHER_HOSTTON)
+        #
+        # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
+        #
+        # This test fails if we don't have <sys/ethernet.h>
+        # or if we do but it doesn't declare ether_hostton().
+        #
+        check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
+        if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
+            #
+            # Yes - we have it declared.
+            #
+            set(HAVE_DECL_ETHER_HOSTTON TRUE)
+        endif()
+    endif()
+    #
+    # Did that succeed?
+    #
+    if(NOT HAVE_DECL_ETHER_HOSTTON)
+        #
+        # No, how about <arpa/inet.h>, as on AIX?
+        #
+        # This test fails if we don't have <arpa/inet.h>
+        # or if we do but it doesn't declare ether_hostton().
+        #
+        check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
+        if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
+            #
+            # Yes - we have it declared.
+            #
+            set(HAVE_DECL_ETHER_HOSTTON TRUE)
+        endif()
+    endif()
+    #
+    # Did that succeed?
+    #
+    if(NOT HAVE_DECL_ETHER_HOSTTON)
+        #
+        # No, how about <netinet/if_ether.h>?
+        # On some platforms, it requires <net/if.h> and
+        # <netinet/in.h>, and we always include it with
+        # both of them, so test it with both of them.
+        #
+        # This test fails if we don't have <netinet/if_ether.h>
+        # and the headers we include before it, or if we do but
+        # <netinet/if_ether.h> doesn't declare ether_hostton().
+        #
+        check_symbol_exists(ether_hostton "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
+        if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
+            #
+            # Yes - we have it declared.
+            #
+            set(HAVE_DECL_ETHER_HOSTTON TRUE)
+        endif()
+    endif()
+    #
+    # After all that, is ether_hostton() declared?
+    #
+    if(NOT HAVE_DECL_ETHER_HOSTTON)
+        #
+        # No, we'll have to declare it ourselves.
+        # Do we have "struct ether_addr" if we include<netinet/if_ether.h>?
+        #
+        check_struct_has_member("struct ether_addr" octet "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" HAVE_STRUCT_ETHER_ADDR)
+    endif()
+endif()
+
 #
 # Large file support on UN*X, a/k/a LFS.
 #
index 2e148dd82f5dafcb0a815c9ee67a7d63fa3f9535..a57776b7b40611e3b55e6b77774074dd366c2858 100644 (file)
@@ -1,5 +1,8 @@
 /* cmakeconfig.h.in */
 
+/* Define to 1 if arpa/inet.h declares `ether_hostton' */
+#cmakedefine ARPA_INET_H_DECLARES_ETHER_HOSTTON 1
+
 /* Enable optimizer debugging */
 #cmakedefine BDEBUG 1
 
@@ -18,8 +21,7 @@
 /* define if you have vdag_set_device_info() */
 #cmakedefine HAVE_DAG_VDAG 1
 
-/* Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
-   don't. */
+/* Define to 1 if you have the declaration of `ether_hostton' */
 #cmakedefine HAVE_DECL_ETHER_HOSTTON 1
 
 /* if passive_req_t primitive exists */
 /* Define to 1 if you have the <memory.h> header file. */
 #cmakedefine HAVE_MEMORY_H 1
 
-/* Define to 1 if you have the <netinet/ether.h> header file. */
-#cmakedefine HAVE_NETINET_ETHER_H 1
-
-/* Define to 1 if you have the <netinet/if_ether.h> header file. */
-#cmakedefine HAVE_NETINET_IF_ETHER_H 1
-
 /* Define to 1 if you have the <netpacket/packet.h> header file. */
 #cmakedefine HAVE_NETPACKET_PACKET_H 1
 
 /* Define to 1 if netinet/if_ether.h declares `ether_hostton' */
 #cmakedefine NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON 1
 
+/* Define to 1 if net/ethernet.h declares `ether_hostton' */
+#cmakedefine NET_ETHERNET_H_DECLARES_ETHER_HOSTTON 1
+
 /* do not use protochain */
 #cmakedefine NO_PROTOCHAIN 1
 
 /* Define to 1 if you have the ANSI C header files. */
 #cmakedefine STDC_HEADERS 1
 
+/* Define to 1 if sys/ethernet.h declares `ether_hostton' */
+#cmakedefine SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON 1
+
 /* Enable parser debugging */
 #cmakedefine YYDEBUG 1
 
index f9a6e8a01c433f4d9f4df003c977d4a864aeaa1d..77eb2ca123043c37294ad652d4b76b769339fe08 100644 (file)
@@ -1,5 +1,8 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* Define to 1 if arpa/inet.h declares `ether_hostton' */
+#undef ARPA_INET_H_DECLARES_ETHER_HOSTTON
+
 /* Enable optimizer debugging */
 #undef BDEBUG
 
@@ -18,8 +21,7 @@
 /* define if you have vdag_set_device_info() */
 #undef HAVE_DAG_VDAG
 
-/* Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
-   don't. */
+/* Define to 1 if you have the declaration of `ether_hostton' */
 #undef HAVE_DECL_ETHER_HOSTTON
 
 /* if passive_req_t primitive exists */
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
-/* Define to 1 if you have the <netinet/ether.h> header file. */
-#undef HAVE_NETINET_ETHER_H
-
-/* Define to 1 if you have the <netinet/if_ether.h> header file. */
-#undef HAVE_NETINET_IF_ETHER_H
-
 /* Define to 1 if you have the <netpacket/packet.h> header file. */
 #undef HAVE_NETPACKET_PACKET_H
 
 /* Define to 1 if netinet/if_ether.h declares `ether_hostton' */
 #undef NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON
 
+/* Define to 1 if net/ethernet.h declares `ether_hostton' */
+#undef NET_ETHERNET_H_DECLARES_ETHER_HOSTTON
+
 /* do not use protochain */
 #undef NO_PROTOCHAIN
 
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Define to 1 if sys/ethernet.h declares `ether_hostton' */
+#undef SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON
+
 /* Enable parser debugging */
 #undef YYDEBUG
 
index c665d2f0acdbf4739217b07005b557a6f9552a9a..3c13b785d6d4d07494bbf9b75a480cc3f339b78b 100755 (executable)
--- a/configure
+++ b/configure
@@ -4660,50 +4660,6 @@ else
 $as_echo "no" >&6; }
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-for ac_header in netinet/if_ether.h
-do :
-  ac_fn_c_check_header_compile "$LINENO" "netinet/if_ether.h" "ac_cv_header_netinet_if_ether_h" "#include <sys/types.h>
-#include <sys/socket.h>
-"
-if test "x$ac_cv_header_netinet_if_ether_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_NETINET_IF_ETHER_H 1
-_ACEOF
-
-fi
-
-done
-
-if test "$ac_cv_header_netinet_if_ether_h" != yes; then
-       #
-       # The simple test didn't work.
-       # Do we need to include <net/if.h> first?
-       # Unset ac_cv_header_netinet_if_ether_h so we don't
-       # treat the previous failure as a cached value and
-       # suppress the next test.
-       #
-       { $as_echo "$as_me:${as_lineno-$LINENO}: Rechecking with some additional includes" >&5
-$as_echo "$as_me: Rechecking with some additional includes" >&6;}
-       unset ac_cv_header_netinet_if_ether_h
-       for ac_header in netinet/if_ether.h
-do :
-  ac_fn_c_check_header_compile "$LINENO" "netinet/if_ether.h" "ac_cv_header_netinet_if_ether_h" "#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-struct mbuf;
-struct rtentry;
-#include <net/if.h>
-"
-if test "x$ac_cv_header_netinet_if_ether_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_NETINET_IF_ETHER_H 1
-_ACEOF
-
-fi
-
-done
-
 fi
 
 case "$host_os" in
@@ -5103,11 +5059,12 @@ fi
 #
 # You are in a twisty little maze of UN*Xes, all different.
 # Some might not have ether_hostton().
-# Some might have it, but not declare it in any header file.
-# Some might have it, but declare it in <netinet/if_ether.h>.
-# Some might have it, but declare it in <netinet/ether.h>
-# (And some might have it but document it as something declared in
-# <netinet/ethernet.h>, although <netinet/if_ether.h> appears to work.)
+# Some might have it and declare it in <net/ethernet.h>.
+# Some might have it and declare it in <netinet/ether.h>
+# Some might have it and declare it in <sys/ethernet.h>.
+# Some might have it and declare it in <arpa/inet.h>.
+# Some might have it and declare it in <netinet/if_ether.h>.
+# Some might have it and not declare it in any header file.
 #
 # Before you is a C compiler.
 #
@@ -5124,27 +5081,46 @@ done
 
 if test "$ac_cv_func_ether_hostton" = yes; then
        #
-       # OK, we have ether_hostton().  Do we have <netinet/if_ether.h>?
+       # OK, we have ether_hostton().  Is it declared in <net/ethernet.h>?
+       #
+       # This test fails if we don't have <net/ethernet.h> or if we do
+       # but it doesn't declare ether_hostton().
+       #
+       ac_fn_c_check_decl "$LINENO" "ether_hostton" "ac_cv_have_decl_ether_hostton" "
+#include <net/ethernet.h>
+
+"
+if test "x$ac_cv_have_decl_ether_hostton" = xyes; then :
+
+
+$as_echo "#define NET_ETHERNET_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
+
+
+fi
+
+       #
+       # Did that succeed?
        #
-       if test "$ac_cv_header_netinet_if_ether_h" = yes; then
+       if test "$ac_cv_have_decl_ether_hostton" != yes; then
+               #
+               # No, how about <netinet/ether.h>, as on Linux?
+               #
+               # This test fails if we don't have <netinet/ether.h>
+               # or if we do but it doesn't declare ether_hostton().
                #
-               # Yes.  Does it declare ether_hostton()?
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
                #
+               unset ac_cv_have_decl_ether_hostton
                ac_fn_c_check_decl "$LINENO" "ether_hostton" "ac_cv_have_decl_ether_hostton" "
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-struct mbuf;
-struct rtentry;
-#include <net/if.h>
-#include <netinet/if_ether.h>
+#include <netinet/ether.h>
 
 "
 if test "x$ac_cv_have_decl_ether_hostton" = xyes; then :
 
 
-$as_echo "#define NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
+$as_echo "#define NETINET_ETHER_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
 
 
 fi
        #
        if test "$ac_cv_have_decl_ether_hostton" != yes; then
                #
-               # No, how about <netinet/ether.h>, as on Linux?
+               # No, how about <sys/ethernet.h>, as on Solaris 10
+                # and later?
                #
-               for ac_header in netinet/ether.h
-do :
-  ac_fn_c_check_header_mongrel "$LINENO" "netinet/ether.h" "ac_cv_header_netinet_ether_h" "$ac_includes_default"
-if test "x$ac_cv_header_netinet_ether_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_NETINET_ETHER_H 1
-_ACEOF
+               # This test fails if we don't have <sys/ethernet.h>
+               # or if we do but it doesn't declare ether_hostton().
+               #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
+               ac_fn_c_check_decl "$LINENO" "ether_hostton" "ac_cv_have_decl_ether_hostton" "
+#include <sys/ethernet.h>
 
-fi
+"
+if test "x$ac_cv_have_decl_ether_hostton" = xyes; then :
 
-done
 
-               if test "$ac_cv_header_netinet_ether_h" = yes; then
-                       #
-                       # We have it - does it declare ether_hostton()?
-                       # Unset ac_cv_have_decl_ether_hostton so we don't
-                       # treat the previous failure as a cached value and
-                       # suppress the next test.
-                       #
-                       unset ac_cv_have_decl_ether_hostton
-                       ac_fn_c_check_decl "$LINENO" "ether_hostton" "ac_cv_have_decl_ether_hostton" "
-#include <netinet/ether.h>
+$as_echo "#define SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
+
+
+fi
+
+       fi
+       #
+       # Did that succeed?
+       #
+       if test "$ac_cv_have_decl_ether_hostton" != yes; then
+               #
+               # No, how about <arpa/inet.h>, as in AIX?
+               #
+               # This test fails if we don't have <arpa/inet.h>
+               # (if we have ether_hostton(), we should have
+               # networking, and if we have networking, we should
+               # have <arapa/inet.h>) or if we do but it doesn't
+               # declare ether_hostton().
+               #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
+               ac_fn_c_check_decl "$LINENO" "ether_hostton" "ac_cv_have_decl_ether_hostton" "
+#include <arpa/inet.h>
 
 "
 if test "x$ac_cv_have_decl_ether_hostton" = xyes; then :
 
 
-$as_echo "#define NETINET_ETHER_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
+$as_echo "#define ARPA_INET_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
 
 
 fi
 
-               fi
        fi
        #
-       # Is ether_hostton() declared?
+       # Did that succeed?
        #
        if test "$ac_cv_have_decl_ether_hostton" != yes; then
+               #
+               # No, how about <netinet/if_ether.h>?
+               # On some platforms, it requires <net/if.h> and
+               # <netinet/in.h>, and we always include it with
+               # both of them, so test it with both of them.
+               #
+               # This test fails if we don't have <netinet/if_ether.h>
+               # and the headers we include before it, or if we do but
+               # <netinet/if_ether.h> doesn't declare ether_hostton().
+               #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
+               ac_fn_c_check_decl "$LINENO" "ether_hostton" "ac_cv_have_decl_ether_hostton" "
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+"
+if test "x$ac_cv_have_decl_ether_hostton" = xyes; then :
+
+
+$as_echo "#define NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON /**/" >>confdefs.h
+
+
+fi
+
+       fi
+       #
+       # After all that, is ether_hostton() declared?
+       #
+       if test "$ac_cv_have_decl_ether_hostton" = yes; then
+               #
+               # Yes.
+               #
+
+$as_echo "#define HAVE_DECL_ETHER_HOSTTON 1" >>confdefs.h
+
+        else
                #
                # No, we'll have to declare it ourselves.
-               # Do we have "struct ether_addr"?
+               # Do we have "struct ether_addr" if we include
+               # <netinet/if_ether.h>?
                #
                ac_fn_c_check_type "$LINENO" "struct ether_addr" "ac_cv_type_struct_ether_addr" "
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-struct mbuf;
-struct rtentry;
 #include <net/if.h>
+#include <netinet/in.h>
 #include <netinet/if_ether.h>
 
 "
@@ -5219,13 +5255,6 @@ _ACEOF
 
 fi
 
-
-$as_echo "#define HAVE_DECL_ETHER_HOSTTON 0" >>confdefs.h
-
-       else
-
-$as_echo "#define HAVE_DECL_ETHER_HOSTTON 1" >>confdefs.h
-
        fi
 fi
 
index 6011ac1eae242c15ab1aaa2f0d596e09347f48d0..3c30c63babb5253702cd9b1030e01add089b3b84 100644 (file)
@@ -67,25 +67,6 @@ if test "$ac_cv_header_net_pfvar_h" = yes; then
            ],
            AC_MSG_RESULT(no))
 fi
-AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
-#include <sys/socket.h>])
-if test "$ac_cv_header_netinet_if_ether_h" != yes; then
-       #
-       # The simple test didn't work.
-       # Do we need to include <net/if.h> first?
-       # Unset ac_cv_header_netinet_if_ether_h so we don't
-       # treat the previous failure as a cached value and
-       # suppress the next test.
-       #
-       AC_MSG_NOTICE([Rechecking with some additional includes])
-       unset ac_cv_header_netinet_if_ether_h
-       AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-struct mbuf;
-struct rtentry;
-#include <net/if.h>])
-fi
 
 case "$host_os" in
 linux*|uclinux*)
@@ -124,37 +105,53 @@ AC_LBL_LIBRARY_NET
 #
 # You are in a twisty little maze of UN*Xes, all different.
 # Some might not have ether_hostton().
-# Some might have it, but not declare it in any header file.
-# Some might have it, but declare it in <netinet/if_ether.h>.
-# Some might have it, but declare it in <netinet/ether.h>
-# (And some might have it but document it as something declared in
-# <netinet/ethernet.h>, although <netinet/if_ether.h> appears to work.)
+# Some might have it and declare it in <net/ethernet.h>.
+# Some might have it and declare it in <netinet/ether.h>
+# Some might have it and declare it in <sys/ethernet.h>.
+# Some might have it and declare it in <arpa/inet.h>.
+# Some might have it and declare it in <netinet/if_ether.h>.
+# Some might have it and not declare it in any header file.
 #
 # Before you is a C compiler.
 #
 AC_CHECK_FUNCS(ether_hostton)
 if test "$ac_cv_func_ether_hostton" = yes; then
        #
-       # OK, we have ether_hostton().  Do we have <netinet/if_ether.h>?
+       # OK, we have ether_hostton().  Is it declared in <net/ethernet.h>?
+       #
+       # This test fails if we don't have <net/ethernet.h> or if we do
+       # but it doesn't declare ether_hostton().
+       #
+       AC_CHECK_DECL(ether_hostton,
+           [
+               AC_DEFINE(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON,,
+                   [Define to 1 if net/ethernet.h declares `ether_hostton'])
+           ],,
+           [
+#include <net/ethernet.h>
+           ])
        #
-       if test "$ac_cv_header_netinet_if_ether_h" = yes; then
+       # Did that succeed?
+       #
+       if test "$ac_cv_have_decl_ether_hostton" != yes; then
+               #
+               # No, how about <netinet/ether.h>, as on Linux?
                #
-               # Yes.  Does it declare ether_hostton()?
+               # This test fails if we don't have <netinet/ether.h>
+               # or if we do but it doesn't declare ether_hostton().
                #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
                AC_CHECK_DECL(ether_hostton,
                    [
-                       AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON,,
-                           [Define to 1 if netinet/if_ether.h declares `ether_hostton'])
+                       AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON,,
+                           [Define to 1 if netinet/ether.h declares `ether_hostton'])
                    ],,
                    [
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-struct mbuf;
-struct rtentry;
-#include <net/if.h>
-#include <netinet/if_ether.h>
+#include <netinet/ether.h>
                    ])
        fi
        #
@@ -162,53 +159,108 @@ struct rtentry;
        #
        if test "$ac_cv_have_decl_ether_hostton" != yes; then
                #
-               # No, how about <netinet/ether.h>, as on Linux?
+               # No, how about <sys/ethernet.h>, as on Solaris 10
+                # and later?
                #
-               AC_CHECK_HEADERS(netinet/ether.h)
-               if test "$ac_cv_header_netinet_ether_h" = yes; then
-                       #
-                       # We have it - does it declare ether_hostton()?
-                       # Unset ac_cv_have_decl_ether_hostton so we don't
-                       # treat the previous failure as a cached value and
-                       # suppress the next test.
-                       #
-                       unset ac_cv_have_decl_ether_hostton
-                       AC_CHECK_DECL(ether_hostton,
-                           [
-                               AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON,,
-                                   [Define to 1 if netinet/ether.h declares `ether_hostton'])
-                           ],,
-                           [
-#include <netinet/ether.h>
-                           ])
-               fi
+               # This test fails if we don't have <sys/ethernet.h>
+               # or if we do but it doesn't declare ether_hostton().
+               #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
+               AC_CHECK_DECL(ether_hostton,
+                   [
+                       AC_DEFINE(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON,,
+                           [Define to 1 if sys/ethernet.h declares `ether_hostton'])
+                   ],,
+                   [
+#include <sys/ethernet.h>
+                   ])
        fi
        #
-       # Is ether_hostton() declared?
+       # Did that succeed?
        #
        if test "$ac_cv_have_decl_ether_hostton" != yes; then
+               #
+               # No, how about <arpa/inet.h>, as in AIX?
+               #
+               # This test fails if we don't have <arpa/inet.h>
+               # (if we have ether_hostton(), we should have
+               # networking, and if we have networking, we should
+               # have <arapa/inet.h>) or if we do but it doesn't
+               # declare ether_hostton().
+               #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
+               AC_CHECK_DECL(ether_hostton,
+                   [
+                       AC_DEFINE(ARPA_INET_H_DECLARES_ETHER_HOSTTON,,
+                           [Define to 1 if arpa/inet.h declares `ether_hostton'])
+                   ],,
+                   [
+#include <arpa/inet.h>
+                   ])
+       fi
+       #
+       # Did that succeed?
+       #
+       if test "$ac_cv_have_decl_ether_hostton" != yes; then
+               #
+               # No, how about <netinet/if_ether.h>?
+               # On some platforms, it requires <net/if.h> and
+               # <netinet/in.h>, and we always include it with
+               # both of them, so test it with both of them.
+               #
+               # This test fails if we don't have <netinet/if_ether.h>
+               # and the headers we include before it, or if we do but
+               # <netinet/if_ether.h> doesn't declare ether_hostton().
+               #
+               # Unset ac_cv_have_decl_ether_hostton so we don't
+               # treat the previous failure as a cached value and
+               # suppress the next test.
+               #
+               unset ac_cv_have_decl_ether_hostton
+               AC_CHECK_DECL(ether_hostton,
+                   [
+                       AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON,,
+                           [Define to 1 if netinet/if_ether.h declares `ether_hostton'])
+                   ],,
+                   [
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+                   ])
+       fi
+       #
+       # After all that, is ether_hostton() declared?
+       #
+       if test "$ac_cv_have_decl_ether_hostton" = yes; then
+               #
+               # Yes.
+               #
+               AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 1,
+                   [Define to 1 if you have the declaration of `ether_hostton'])
+        else
                #
                # No, we'll have to declare it ourselves.
-               # Do we have "struct ether_addr"?
+               # Do we have "struct ether_addr" if we include
+               # <netinet/if_ether.h>?
                #
                AC_CHECK_TYPES(struct ether_addr,,,
                    [
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-struct mbuf;
-struct rtentry;
 #include <net/if.h>
+#include <netinet/in.h>
 #include <netinet/if_ether.h>
                    ])
-               AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 0,
-                   [Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
-don't.])
-       else
-               AC_DEFINE(HAVE_DECL_ETHER_HOSTTON, 1,
-                   [Define to 1 if you have the declaration of `ether_hostton', and to 0 if you
-don't.])
        fi
 fi
 
index c22590ce58aaec9b425dabe6bbec76be7fee6930..6ffb64b61b5d72d89eca1cc78974299a868235a1 100644 (file)
 #endif
 
 #ifdef _WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-
-#ifdef INET6
-/*
- * To quote the MSDN page for getaddrinfo() at
- *
- *    https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx
- *
- * "Support for getaddrinfo on Windows 2000 and older versions
- * The getaddrinfo function was added to the Ws2_32.dll on Windows XP and
- * later. To execute an application that uses this function on earlier
- * versions of Windows, then you need to include the Ws2tcpip.h and
- * Wspiapi.h files. When the Wspiapi.h include file is added, the
- * getaddrinfo function is defined to the WspiapiGetAddrInfo inline
- * function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo
- * function is implemented in such a way that if the Ws2_32.dll or the
- * Wship6.dll (the file containing getaddrinfo in the IPv6 Technology
- * Preview for Windows 2000) does not include getaddrinfo, then a
- * version of getaddrinfo is implemented inline based on code in the
- * Wspiapi.h header file. This inline code will be used on older Windows
- * platforms that do not natively support the getaddrinfo function."
- *
- * We use getaddrinfo(), so we include Wspiapi.h here.
- */
-#include <Wspiapi.h>
-#endif
-
+  #include <winsock2.h>
+  #include <ws2tcpip.h>
+
+  #ifdef INET6
+    /*
+     * To quote the MSDN page for getaddrinfo() at
+     *
+     *    https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx
+     *
+     * "Support for getaddrinfo on Windows 2000 and older versions
+     * The getaddrinfo function was added to the Ws2_32.dll on Windows XP and
+     * later. To execute an application that uses this function on earlier
+     * versions of Windows, then you need to include the Ws2tcpip.h and
+     * Wspiapi.h files. When the Wspiapi.h include file is added, the
+     * getaddrinfo function is defined to the WspiapiGetAddrInfo inline
+     * function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo
+     * function is implemented in such a way that if the Ws2_32.dll or the
+     * Wship6.dll (the file containing getaddrinfo in the IPv6 Technology
+     * Preview for Windows 2000) does not include getaddrinfo, then a
+     * version of getaddrinfo is implemented inline based on code in the
+     * Wspiapi.h header file. This inline code will be used on older Windows
+     * platforms that do not natively support the getaddrinfo function."
+     *
+     * We use getaddrinfo(), so we include Wspiapi.h here.
+     */
+    #include <Wspiapi.h>
+  #endif /* INET6 */
 #else /* _WIN32 */
-
-#include <sys/param.h>
-#include <sys/types.h>                         /* concession to AIX */
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netinet/in.h>
-#endif /* _WIN32 */
-
-#ifndef _WIN32
-#ifdef HAVE_ETHER_HOSTTON
-/*
- * XXX - do we need any of this if <netinet/if_ether.h> doesn't declare
- * ether_hostton()?
- */
-#ifdef HAVE_NETINET_IF_ETHER_H
-struct mbuf;           /* Squelch compiler warnings on some platforms for */
-struct rtentry;                /* declarations in <net/if.h> */
-#include <net/if.h>    /* for "struct ifnet" in "struct arpcom" on Solaris */
-#include <netinet/if_ether.h>
-#endif /* HAVE_NETINET_IF_ETHER_H */
-#ifdef NETINET_ETHER_H_DECLARES_ETHER_HOSTTON
-#include <netinet/ether.h>
-#endif /* NETINET_ETHER_H_DECLARES_ETHER_HOSTTON */
-#endif /* HAVE_ETHER_HOSTTON */
-#include <arpa/inet.h>
-#include <netdb.h>
+  #include <sys/param.h>
+  #include <sys/types.h>                       /* concession to AIX */
+  #include <sys/socket.h>
+  #include <sys/time.h>
+
+  #include <netinet/in.h>
+
+  #ifdef HAVE_ETHER_HOSTTON
+    #if defined(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
+      /*
+       * OK, just include <net/ethernet.h>.
+       */
+      #include <net/ethernet.h>
+    #elif defined(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
+      /*
+       * OK, just include <netinet/ether.h>
+       */
+      #include <netinet/ether.h>
+    #elif defined(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
+      /*
+       * OK, just include <sys/ethernet.h>
+       */
+      #include <sys/ethernet.h>
+    #elif defined(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
+      /*
+       * OK, just include <arpa/inet.h>
+       */
+      #include <arpa/inet.h>
+    #elif defined(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
+      /*
+       * 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 /* HAVE_STRUCT_ETHER_ADDR */
+       struct ether_addr {
+               unsigned char ether_addr_octet[6];
+       };
+      #endif /* HAVE_STRUCT_ETHER_ADDR */
+    #endif
+
+    #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_HOSTTON
+      /*
+       * No header declares it, so declare it ourselves.
+       */
+      extern int ether_hostton(const char *, struct ether_addr *);
+    #endif /* defined(HAVE_DECL_ETHER_HOSTTON) || !HAVE_DECL_ETHER_HOSTTON */
+  #endif /* HAVE_ETHER_HOSTTON */
+
+  #include <arpa/inet.h>
+  #include <netdb.h>
 #endif /* _WIN32 */
 
 #include <ctype.h>
@@ -502,16 +539,6 @@ pcap_ether_hostton(const char *name)
        return (NULL);
 }
 #else
-
-#if !defined(HAVE_DECL_ETHER_HOSTTON) || !HAVE_DECL_ETHER_HOSTTON
-#ifndef HAVE_STRUCT_ETHER_ADDR
-struct ether_addr {
-       unsigned char ether_addr_octet[6];
-};
-#endif
-extern int ether_hostton(const char *, struct ether_addr *);
-#endif
-
 /* Use the os supplied routines */
 u_char *
 pcap_ether_hostton(const char *name)