26#include <freeradius-devel/util/inet.h>
110 struct in6_addr
zero = {};
176 fr_inet_pton4(&addr,
"192.168.1.1", -1,
false,
false,
false);
179 TEST_MSG(
"expected 192.168.1.1, got %s", buf);
185 TEST_MSG(
"expected ::1, got %s", buf);
200 TEST_MSG(
"expected 10.0.0.0/8, got %s", buf);
210 TEST_CASE(
"Same address compares equal");
215 TEST_CASE(
"Different addresses compare non-equal");
225 TEST_CASE(
"IPv4 vs IPv6 comparison (different af)");
239 fr_inet_pton4(&addr,
"192.168.1.100", -1,
false,
false,
false);
248 TEST_CASE(
"Mask to /0 clears everything");
249 fr_inet_pton4(&addr,
"255.255.255.255", -1,
false,
false,
false);
293 TEST_CASE(
"/128 is not a prefix (IPv6)");
333 struct sockaddr_storage sa;
338 fr_inet_pton4(&addr,
"192.168.1.1", -1,
false,
false,
false);
int fr_ipaddr_is_prefix(fr_ipaddr_t const *ipaddr)
Determine if an address is a prefix.
char * fr_inet_ntop_prefix(char out[static FR_IPADDR_PREFIX_STRLEN], size_t outlen, fr_ipaddr_t const *addr)
Print a fr_ipaddr_t as a CIDR style network prefix.
int fr_inet_pton6(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask)
Parse an IPv6 address or IPv6 prefix in presentation format (and others)
int fr_ipaddr_from_sockaddr(fr_ipaddr_t *ipaddr, uint16_t *port, struct sockaddr_storage const *sa, socklen_t salen)
Convert sockaddr to our internal ip address representation.
int fr_inet_pton(fr_ipaddr_t *out, char const *value, ssize_t inlen, int af, bool resolve, bool mask)
Simple wrapper to decide whether an IP value is v4 or v6 and call the appropriate parser.
int fr_inet_pton_port(fr_ipaddr_t *out, uint16_t *port_out, char const *value, ssize_t inlen, int af, bool resolve, bool mask)
Parses IPv4/6 address + port, to fr_ipaddr_t and integer (port)
int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
Determine if an address is the INADDR_ANY address for its address family.
char * fr_inet_ntop(char out[static FR_IPADDR_STRLEN], size_t outlen, fr_ipaddr_t const *addr)
Print the address portion of a fr_ipaddr_t.
int fr_ipaddr_to_sockaddr(struct sockaddr_storage *sa, socklen_t *salen, fr_ipaddr_t const *ipaddr, uint16_t port)
Convert our internal ip address representation to a sockaddr.
int8_t fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
Compare two ip addresses.
void fr_ipaddr_mask(fr_ipaddr_t *addr, uint8_t prefix)
Zeroes out the host portion of an fr_ipaddr_t.
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
#define FR_IPADDR_STRLEN
Like INET6_ADDRSTRLEN but includes space for the textual Zone ID.
union fr_ipaddr_t::@137 addr
#define FR_IPADDR_PREFIX_STRLEN
Like FR_IPADDR_STRLEN but with space for a prefix.
static void test_ipaddr_mask(void)
static void test_inet_ntop(void)
static void test_inet_pton4_prefix(void)
static void test_ipaddr_cmp(void)
static void test_inet_pton4_basic(void)
static void test_inet_pton_auto(void)
static void test_inet_pton_port(void)
static void test_inet_pton6_prefix(void)
static void test_inet_pton6_basic(void)
static void test_inet_ntop_prefix(void)
static void test_ipaddr_is_prefix(void)
static void test_ipaddr_is_inaddr_any(void)
static void test_inet_pton4_invalid(void)
static void test_ipaddr_sockaddr(void)
static const uint8_t * zero
int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)