packets: Add ipv6_string_mapped.
authorThadeu Lima de Souza Cascardo <cascardo@redhat.com>
Wed, 25 Nov 2015 13:31:06 +0000 (11:31 -0200)
committerBen Pfaff <blp@ovn.org>
Mon, 30 Nov 2015 18:10:29 +0000 (10:10 -0800)
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>
Signed-off-by: Ben Pfaff <blp@ovn.org>
lib/packets.c
lib/packets.h

index 0f72891..6a3dd9c 100644 (file)
@@ -489,6 +489,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)
 {
index 2ad268a..970fc31 100644 (file)
@@ -959,6 +959,7 @@ void ipv6_format_addr_bracket(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);