tests: Add bundle action test with buffer realloc.
[cascardo/ovs.git] / lib / socket-util.c
index 206e17b..6f959b2 100644 (file)
@@ -136,13 +136,22 @@ set_dscp(int fd, int family, uint8_t dscp)
     return retval ? sock_errno() : 0;
 }
 
+/* Checks whether 'host_name' is an IPv4 or IPv6 address.  It is assumed
+ * that 'host_name' is valid.  Returns false if it is IPv4 address, true if
+ * it is IPv6 address. */
+bool
+addr_is_ipv6(const char *host_name)
+{
+    return strchr(host_name, ':') != NULL;
+}
+
 /* Translates 'host_name', which must be a string representation of an IP
  * address, into a numeric IP address in '*addr'.  Returns 0 if successful,
  * otherwise a positive errno value. */
 int
 lookup_ip(const char *host_name, struct in_addr *addr)
 {
-    if (!inet_pton(AF_INET, host_name, addr)) {
+    if (!ip_parse(host_name, &addr->s_addr)) {
         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
         VLOG_ERR_RL(&rl, "\"%s\" is not a valid IP address", host_name);
         return ENOENT;
@@ -156,7 +165,7 @@ lookup_ip(const char *host_name, struct in_addr *addr)
 int
 lookup_ipv6(const char *host_name, struct in6_addr *addr)
 {
-    if (inet_pton(AF_INET6, host_name, addr) != 1) {
+    if (!ipv6_parse(host_name, addr)) {
         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
         VLOG_ERR_RL(&rl, "\"%s\" is not a valid IPv6 address", host_name);
         return ENOENT;
@@ -179,7 +188,7 @@ lookup_hostname(const char *host_name, struct in_addr *addr)
     struct addrinfo *result;
     struct addrinfo hints;
 
-    if (inet_pton(AF_INET, host_name, addr)) {
+    if (ip_parse(host_name, &addr->s_addr)) {
         return 0;
     }
 
@@ -362,14 +371,14 @@ parse_sockaddr_components(struct sockaddr_storage *ss,
 
         sin6->sin6_family = AF_INET6;
         sin6->sin6_port = htons(port);
-        if (!inet_pton(AF_INET6, host_s, sin6->sin6_addr.s6_addr)) {
+        if (!ipv6_parse(host_s, &sin6->sin6_addr)) {
             VLOG_ERR("%s: bad IPv6 address \"%s\"", s, host_s);
             goto exit;
         }
     } else {
         sin->sin_family = AF_INET;
         sin->sin_port = htons(port);
-        if (!inet_pton(AF_INET, host_s, &sin->sin_addr.s_addr)) {
+        if (!ip_parse(host_s, &sin->sin_addr.s_addr)) {
             VLOG_ERR("%s: bad IPv4 address \"%s\"", s, host_s);
             goto exit;
         }