]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: net_gethostbyname() now supports [ipv6] style bracketed addresses.
authorTimo Sirainen <tss@iki.fi>
Mon, 19 Oct 2015 11:05:26 +0000 (14:05 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 19 Oct 2015 11:05:26 +0000 (14:05 +0300)
src/lib/net.c

index bb4eff1a44677658403171a8c65046e5897578c2..f998cb9512ea9e90a45c1598496666856cc1c484 100644 (file)
@@ -628,6 +628,7 @@ int net_gethostbyname(const char *addr, struct ip_addr **ips,
 #ifdef HAVE_IPV6
        union sockaddr_union *so;
        struct addrinfo hints, *ai, *origai;
+       struct ip_addr ip;
        int host_error;
 #else
        struct hostent *hp;
@@ -638,6 +639,14 @@ int net_gethostbyname(const char *addr, struct ip_addr **ips,
         *ips_count = 0;
 
 #ifdef HAVE_IPV6
+       /* support [ipv6] style addresses here so they work globally */
+       if (addr[0] == '[' && net_addr2ip(addr, &ip) == 0) {
+               *ips_count = 1;
+               *ips = t_new(struct ip_addr, 1);
+               **ips = ip;
+               return 0;
+       }
+
        memset(&hints, 0, sizeof(struct addrinfo));
        hints.ai_socktype = SOCK_STREAM;