]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Alternative source of sockaddr_ll for emscripten/musl
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 27 Apr 2022 20:31:54 +0000 (15:31 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 27 Apr 2022 20:54:09 +0000 (15:54 -0500)
configure
configure.ac
src/include/autoconf.h.in
src/lib/util/inet.c
src/lib/util/pcap.c
src/lib/util/socket.c
src/lib/util/struct.c

index 8a27c940e2e6301c648864080f10d78af087a4aa..2941c5b924b739ab9459d1277755e9d41cd55b7d 100755 (executable)
--- a/configure
+++ b/configure
@@ -9060,6 +9060,12 @@ if test "x$ac_cv_header_malloc_h" = xyes
 then :
   printf "%s\n" "#define HAVE_MALLOC_H 1" >>confdefs.h
 
+fi
+ac_fn_c_check_header_compile "$LINENO" "net/if_dl.h" "ac_cv_header_net_if_dl_h" "$ac_includes_default"
+if test "x$ac_cv_header_net_if_dl_h" = xyes
+then :
+  printf "%s\n" "#define HAVE_NET_IF_DL_H 1" >>confdefs.h
+
 fi
 ac_fn_c_check_header_compile "$LINENO" "netdb.h" "ac_cv_header_netdb_h" "$ac_includes_default"
 if test "x$ac_cv_header_netdb_h" = xyes
@@ -9072,6 +9078,12 @@ if test "x$ac_cv_header_netinet_in_h" = xyes
 then :
   printf "%s\n" "#define HAVE_NETINET_IN_H 1" >>confdefs.h
 
+fi
+ac_fn_c_check_header_compile "$LINENO" "netpacket/packet.h" "ac_cv_header_netpacket_packet_h" "$ac_includes_default"
+if test "x$ac_cv_header_netpacket_packet_h" = xyes
+then :
+  printf "%s\n" "#define HAVE_NETPACKET_PACKET_H 1" >>confdefs.h
+
 fi
 ac_fn_c_check_header_compile "$LINENO" "prot.h" "ac_cv_header_prot_h" "$ac_includes_default"
 if test "x$ac_cv_header_prot_h" = xyes
index 4148085075db227a7516cbad6f2734373beef11b..d4e915aae86f277ad0fca92f61a606a54e901561 100644 (file)
@@ -951,8 +951,10 @@ AC_CHECK_HEADERS( \
   limits.h \
   linux/if_packet.h \
   malloc.h \
+  net/if_dl.h \
   netdb.h \
   netinet/in.h \
+  netpacket/packet.h \
   prot.h \
   pwd.h \
   resource.h \
index da79d1f1f1131b63dd96acfa984a1123d7e2da58..f6557732ce760cbf80086bb99f45007f88d990a2 100644 (file)
 /* Define to 1 if you have the <netinet/in.h> header file. */
 #undef HAVE_NETINET_IN_H
 
+/* Define to 1 if you have the <netpacket/packet.h> header file. */
+#undef HAVE_NETPACKET_PACKET_H
+
+/* Define to 1 if you have the <net/if_dl.h> header file. */
+#undef HAVE_NET_IF_DL_H
+
 /* Define to 1 if you have the <net/if.h> header file. */
 #undef HAVE_NET_IF_H
 
index b805666964804d117ab76f6f9638519c0d9cba90..061009aef816cb5f7083ed026ff139b2052316f1 100644 (file)
 
 #include <stdlib.h>
 #include <ifaddrs.h>
+#include <net/if_arp.h>
 
-#ifdef HAVE_LINUX_IF_PACKET_H
+/*
+ *     Linux
+ */
+#if defined(HAVE_LINUX_IF_PACKET_H)
 #  include <linux/if_packet.h>
 #  include <linux/if_ether.h>
-#endif
-
-#include <net/if_arp.h>
-
 /*
  *     Apple, *BSD
  */
-#ifndef __linux__
-#include <net/if_dl.h>
+#elif defined(HAVE_NET_IF_DL_H)
+#  include <net/if_dl.h>                /* Needed for struct sockaddr_ll def */
+/*
+ *     emscripten/musl
+ */
+#elif defined(HAVE_NETPACKET_PACKET_H)
+#  include <netpacket/packet.h>                /* Needed for struct sockaddr_ll def */
 #endif
 
 bool fr_reverse_lookups = false;               //!< IP -> hostname lookups?
@@ -64,7 +69,8 @@ int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
 
 #ifdef HAVE_STRUCT_SOCKADDR_IN6
        } else if (ipaddr->af == AF_INET6) {
-               if (IN6_IS_ADDR_UNSPECIFIED(&(ipaddr->addr.v6))) {
+               /* Unconst for emscripten/musl */
+               if (IN6_IS_ADDR_UNSPECIFIED(UNCONST(struct in6_addr *, &(ipaddr->addr.v6)))) {
                        return 1;
                }
 #endif
@@ -94,7 +100,8 @@ int fr_ipaddr_is_multicast(fr_ipaddr_t const *ipaddr)
                if ((ipaddr->addr.v4.s_addr >= 3758096384) && (ipaddr->addr.v4.s_addr <= 4026531839)) return 1;
 #ifdef HAVE_STRUCT_SOCKADDR_IN6
        } else if (ipaddr->af == AF_INET6) {
-               if (IN6_IS_ADDR_MULTICAST(&(ipaddr->addr.v6))) {
+               /* Unconst for emscripten/musl */
+               if (IN6_IS_ADDR_MULTICAST(UNCONST(struct in6_addr *, &(ipaddr->addr.v6)))) {
                        return 1;
                }
 #endif
@@ -1550,7 +1557,7 @@ int fr_interface_to_ethernet(char const *interface, fr_ethernet_t *ethernet)
                if (!i->ifa_addr || !i->ifa_name || (i->ifa_addr->sa_family != AF_LINK)) continue;
                if (strcmp(i->ifa_name, interface) != 0) continue;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__EMSCRIPTEN__)
                struct sockaddr_ll *ll;
 
                ll = (struct sockaddr_ll *) i->ifa_addr;
index 55a88ff79f4ed8c55d7742f1517aa4532572f4c1..60332a824405cb09959b3e955e1ae43482d6258a 100644 (file)
@@ -34,7 +34,9 @@
 
 #ifndef SIOCGIFHWADDR
 #  include <ifaddrs.h>
-#  include <net/if_dl.h>
+#  ifdef HAVE_NET_IF_DL_H
+#    include <net/if_dl.h>
+#  endif
 #else
 #  include <net/if.h>
 #endif
index c17947225f7354c946408ce5a4ee5046b78c4935..4b4d630cdd88c70c07cfca2b882815fa7bc72daf 100644 (file)
@@ -135,7 +135,8 @@ static int socket_inaddr_any_v6only(int sockfd, fr_ipaddr_t const *ipaddr)
         */
        if (ipaddr->af == AF_INET6) {
 #  ifdef IPV6_V6ONLY
-               if (IN6_IS_ADDR_UNSPECIFIED(&ipaddr->addr.v6)) {
+               /* unconst for emscripten/musl */
+               if (IN6_IS_ADDR_UNSPECIFIED(UNCONST(struct in6_addr *, &ipaddr->addr.v6))) {
                        int on = 1;
 
                        if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY,
index 562074d170e2b45299b8636126635e37ea68e2f3..2059571554ce102833755061b509c7cce6f0237b 100644 (file)
@@ -131,7 +131,7 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_pair_list_t *out,
                        uint64_t value;
 
                        num_bits = offset + child->flags.length;
-                       if ((end - p) < fr_bytes_from_bits(num_bits)) {
+                       if ((size_t)(end - p) < fr_bytes_from_bits(num_bits)) {
                                FR_PROTO_TRACE("not enough data for bit decoder?");
                                goto unknown;
                        }