From: Alan T. DeKok Date: Wed, 3 May 2017 15:27:29 +0000 (-0400) Subject: move fr_is_inaddr_any to socket.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36b1e4cae4c80ddcf9dfd37dc4623e77bc7a3c0c;p=thirdparty%2Ffreeradius-server.git move fr_is_inaddr_any to socket.c --- diff --git a/src/include/libradius.h b/src/include/libradius.h index db9f63458f3..3ec28d557f8 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -519,6 +519,7 @@ int fr_socket_client_tcp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_ int fr_socket_wait_for_connect(int sockfd, struct timeval const *timeout); int fr_socket_server_base(int proto, fr_ipaddr_t *ipaddr, int *port, char const *port_name, bool async); int fr_socket_server_bind(int sockfd, fr_ipaddr_t *ipaddr, int *port, char const *interface); +int fr_is_inaddr_any(fr_ipaddr_t *ipaddr); #ifdef __cplusplus } diff --git a/src/include/packet.h b/src/include/packet.h index 1bc47b1bb8a..b587e76c50d 100644 --- a/src/include/packet.h +++ b/src/include/packet.h @@ -30,7 +30,6 @@ extern "C" { #endif int fr_packet_cmp(RADIUS_PACKET const *a, RADIUS_PACKET const *b); -int fr_is_inaddr_any(fr_ipaddr_t *ipaddr); void fr_request_from_reply(RADIUS_PACKET *request, RADIUS_PACKET const *reply); diff --git a/src/lib/util/socket.c b/src/lib/util/socket.c index 81513bad803..d7a9dc8a139 100644 --- a/src/lib/util/socket.c +++ b/src/lib/util/socket.c @@ -807,3 +807,35 @@ int fr_socket(fr_ipaddr_t const *ipaddr, uint16_t port) return sockfd; } + + +/** Determine if an address is the INADDR_ANY address for its address family + * + * @param ipaddr to check. + * @return + * - 0 if it's not. + * - 1 if it is. + * - -1 on error. + */ +int fr_is_inaddr_any(fr_ipaddr_t *ipaddr) +{ + + if (ipaddr->af == AF_INET) { + if (ipaddr->ipaddr.ip4addr.s_addr == INADDR_ANY) { + return 1; + } + +#ifdef HAVE_STRUCT_SOCKADDR_IN6 + } else if (ipaddr->af == AF_INET6) { + if (IN6_IS_ADDR_UNSPECIFIED(&(ipaddr->ipaddr.ip6addr))) { + return 1; + } +#endif + + } else { + fr_strerror_printf("Unknown address family"); + return -1; + } + + return 0; +} diff --git a/src/protocols/radius/list.c b/src/protocols/radius/list.c index 8e837c8c388..a1a1b20eb69 100644 --- a/src/protocols/radius/list.c +++ b/src/protocols/radius/list.c @@ -86,38 +86,6 @@ int fr_packet_cmp(RADIUS_PACKET const *a, RADIUS_PACKET const *b) return rcode; } -/** Determine if an address is the INADDR_ANY address for its address family - * - * @param ipaddr to check. - * @return - * - 0 if it's not. - * - 1 if it is. - * - -1 on error. - */ -int fr_is_inaddr_any(fr_ipaddr_t *ipaddr) -{ - - if (ipaddr->af == AF_INET) { - if (ipaddr->ipaddr.ip4addr.s_addr == INADDR_ANY) { - return 1; - } - -#ifdef HAVE_STRUCT_SOCKADDR_IN6 - } else if (ipaddr->af == AF_INET6) { - if (IN6_IS_ADDR_UNSPECIFIED(&(ipaddr->ipaddr.ip6addr))) { - return 1; - } -#endif - - } else { - fr_strerror_printf("Unknown address family"); - return -1; - } - - return 0; -} - - /* * Create a fake "request" from a reply, for later lookup. */