27 RCSIDH(inet_h,
"$Id: 875d39fc4536d78f1c461fc584c3efc06ba2940b $")
30 #include <arpa/inet.h>
44 struct in_addr ip4addr;
45 struct in6_addr ip6addr;
55 # if defined(SIOCGIFADDR) && (defined(SIOCGIFNAME) || defined(HAVE_IF_INDEXTONAME))
56 # define WITH_IFINDEX_RESOLUTION 1
59 # if defined(SIOCGIFNAME) || defined(HAVE_IF_INDEXTONAME)
60 # define WITH_IFINDEX_NAME_RESOLUTION 1
67 #define FR_IPADDR_STRLEN (INET6_ADDRSTRLEN + 1 + IFNAMSIZ)
71 #define FR_IPADDR_PREFIX_STRLEN (FR_IPADDR_STRLEN + 1 + 3)
92 ssize_t inlen,
int af,
bool resolve,
bool mask);
107 #ifdef WITH_IFINDEX_NAME_RESOLUTION
108 char *fr_ifname_from_ifindex(
char out[IFNAMSIZ],
int if_index);
111 #ifdef WITH_IFINDEX_IPADDR_RESOLUTION
112 int fr_ipaddr_from_ifindex(
fr_ipaddr_t *out,
int fd,
int af,
int if_index);
124 struct sockaddr_storage *sa, socklen_t *salen);
int fr_ipaddr_from_sockaddr(struct sockaddr_storage const *sa, socklen_t salen, fr_ipaddr_t *ipaddr, uint16_t *port)
int fr_inet_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback)
Wrappers for IPv4/IPv6 host to IP address lookup.
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
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)
char * fr_inet_ntop_prefix(char out[FR_IPADDR_PREFIX_STRLEN], size_t outlen, fr_ipaddr_t *addr)
Print a fr_ipaddr_t as a CIDR style network prefix.
static char const * hostname(char *buf, size_t buflen, uint32_t ipaddr)
#define FR_IPADDR_STRLEN
Like INET6_ADDRSTRLEN but includes space for the textual Zone ID.
char * fr_inet_ifid_ntop(char *out, size_t outlen, uint8_t const *ifid)
Print an interface-id in standard colon notation.
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...
union fr_ipaddr_t::@1 ipaddr
int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask)
Parse an IPv4 address or IPv4 prefix in presentation format (and others)
struct fr_ipaddr_t fr_ipaddr_t
IPv4/6 prefix.
void fr_ipaddr_mask(fr_ipaddr_t *addr, uint8_t prefix)
Zeroes out the host portion of an fr_ipaddr_t.
static char const * prefix
struct in6_addr fr_inet_link_local6
uint32_t zone_id
A host may have multiple link-local interfaces the scope ID allows the application to specify which o...
uint8_t * fr_inet_ifid_pton(uint8_t out[8], char const *ifid_str)
Convert interface-id in colon notation to 8 byte binary form.
char * fr_inet_ntop(char out[FR_IPADDR_STRLEN], size_t outlen, fr_ipaddr_t *addr)
Print the address portion of a fr_ipaddr_t.
int fr_ipaddr_from_ifname(fr_ipaddr_t *out, int af, char const *name)
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)
char const * fr_inet_ntoh(fr_ipaddr_t const *src, char *out, size_t outlen)
Perform reverse resolution of an IP address.
int fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
Compare two ip addresses.
#define FR_IPADDR_PREFIX_STRLEN
Like FR_IPADDR_STRLEN but with space for a prefix.
int fr_ipaddr_to_sockaddr(fr_ipaddr_t const *ipaddr, uint16_t port, struct sockaddr_storage *sa, socklen_t *salen)