@@ -474,6 +474,21 @@ ipv6_format_masked(const struct in6_addr *addr, const struct in6_addr *mask,
}
}
+/* Stores the string representation of the IPv6 address 'addr' into the
+ * character array 'addr_str', which must be at least INET6_ADDRSTRLEN
+ * bytes long. If addr is IPv4-mapped, store an IPv4 dotted-decimal string. */
+const char *
+ipv6_string_mapped(char *addr_str, const struct in6_addr *addr)
+{
+ ovs_be32 ip;
+ ip = in6_addr_get_mapped_ipv4(addr);
+ if (ip) {
+ return inet_ntop(AF_INET, &ip, addr_str, INET6_ADDRSTRLEN);
+ } else {
+ return inet_ntop(AF_INET6, addr, addr_str, INET6_ADDRSTRLEN);
+ }
+}
+
struct in6_addr ipv6_addr_bitand(const struct in6_addr *a,
const struct in6_addr *b)
{
@@ -954,6 +954,7 @@ void ipv6_format_addr(const struct in6_addr *addr, struct ds *);
void ipv6_format_mapped(const struct in6_addr *addr, struct ds *);
void ipv6_format_masked(const struct in6_addr *addr,
const struct in6_addr *mask, struct ds *);
+const char * ipv6_string_mapped(char *addr_str, const struct in6_addr *addr);
struct in6_addr ipv6_addr_bitand(const struct in6_addr *src,
const struct in6_addr *mask);
struct in6_addr ipv6_create_mask(int mask);
ipv6_string_mapped stores an IPv6 or IPv4 representation of an IPv6 address into a string. If the address is IPv4-mapped, it's represented in IPv4 dotted-decimal format. Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com> --- lib/packets.c | 15 +++++++++++++++ lib/packets.h | 1 + 2 files changed, 16 insertions(+)