From: Arran Cudbard-Bell Date: Wed, 27 Apr 2022 20:31:54 +0000 (-0500) Subject: Alternative source of sockaddr_ll for emscripten/musl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbb928263cba858de554ac24b66908a508aeee23;p=thirdparty%2Ffreeradius-server.git Alternative source of sockaddr_ll for emscripten/musl --- diff --git a/configure b/configure index 8a27c940e2e..2941c5b924b 100755 --- 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 diff --git a/configure.ac b/configure.ac index 4148085075d..d4e915aae86 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/src/include/autoconf.h.in b/src/include/autoconf.h.in index da79d1f1f11..f6557732ce7 100644 --- a/src/include/autoconf.h.in +++ b/src/include/autoconf.h.in @@ -266,6 +266,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_IN_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETPACKET_PACKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NET_IF_DL_H + /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_H diff --git a/src/lib/util/inet.c b/src/lib/util/inet.c index b8056669648..061009aef81 100644 --- a/src/lib/util/inet.c +++ b/src/lib/util/inet.c @@ -28,19 +28,24 @@ #include #include +#include -#ifdef HAVE_LINUX_IF_PACKET_H +/* + * Linux + */ +#if defined(HAVE_LINUX_IF_PACKET_H) # include # include -#endif - -#include - /* * Apple, *BSD */ -#ifndef __linux__ -#include +#elif defined(HAVE_NET_IF_DL_H) +# include /* Needed for struct sockaddr_ll def */ +/* + * emscripten/musl + */ +#elif defined(HAVE_NETPACKET_PACKET_H) +# include /* 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; diff --git a/src/lib/util/pcap.c b/src/lib/util/pcap.c index 55a88ff79f4..60332a82440 100644 --- a/src/lib/util/pcap.c +++ b/src/lib/util/pcap.c @@ -34,7 +34,9 @@ #ifndef SIOCGIFHWADDR # include -# include +# ifdef HAVE_NET_IF_DL_H +# include +# endif #else # include #endif diff --git a/src/lib/util/socket.c b/src/lib/util/socket.c index c17947225f7..4b4d630cdd8 100644 --- a/src/lib/util/socket.c +++ b/src/lib/util/socket.c @@ -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, diff --git a/src/lib/util/struct.c b/src/lib/util/struct.c index 562074d170e..2059571554c 100644 --- a/src/lib/util/struct.c +++ b/src/lib/util/struct.c @@ -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; }