]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added support for [] around ipv6 addresses everywhere.
authorTimo Sirainen <tss@iki.fi>
Tue, 1 Jun 2010 17:35:48 +0000 (18:35 +0100)
committerTimo Sirainen <tss@iki.fi>
Tue, 1 Jun 2010 17:35:48 +0000 (18:35 +0100)
--HG--
branch : HEAD

src/config/old-set-parser.c
src/lib/network.c
src/master/service.c

index 56cfdb523b18e7e859132b3adc795f01b9eb67f3..16cba0dc0796a6ec7f5a05f52499ba11a6cb77d6 100644 (file)
@@ -215,6 +215,7 @@ static bool listen_has_port(const char *str)
        for (; *addrs != NULL; addrs++) {
                if (strcmp(*addrs, "*") != 0 &&
                    strcmp(*addrs, "::") != 0 &&
+                   strcmp(*addrs, "[::]") != 0 &&
                    !is_ipv4_address(*addrs) &&
                    !is_ipv6_address(*addrs))
                        return TRUE;
index c04c5b2f850462f9eea19af4663766204c25d5fb..5abc5cd83560dd11b1dcf98aa01d4adcbc802b39 100644 (file)
@@ -678,11 +678,22 @@ const char *net_ip2addr(const struct ip_addr *ip)
 
 int net_addr2ip(const char *addr, struct ip_addr *ip)
 {
+       int ret;
+
        if (strchr(addr, ':') != NULL) {
                /* IPv6 */
                ip->family = AF_INET6;
 #ifdef HAVE_IPV6
-               if (inet_pton(AF_INET6, addr, &ip->u.ip6) == 0)
+               T_BEGIN {
+                       if (addr[0] == '[') {
+                               /* allow [ipv6 addr] */
+                               unsigned int len = strlen(addr);
+                               if (addr[len-1] == ']')
+                                       addr = t_strndup(addr+1, len-2);
+                       }
+                       ret = inet_pton(AF_INET6, addr, &ip->u.ip6);
+               } T_END;
+               if (ret == 0)
                        return -1;
 #else
                ip->u.ip4.s_addr = 0;
@@ -785,9 +796,18 @@ bool is_ipv4_address(const char *addr)
 
 bool is_ipv6_address(const char *addr)
 {
+       bool have_prefix = FALSE;
+
+       if (*addr == '[') {
+               have_prefix = TRUE;
+               addr++;
+       }
        while (*addr != '\0') {
-               if (*addr != ':' && !i_isxdigit(*addr))
+               if (*addr != ':' && !i_isxdigit(*addr)) {
+                       if (have_prefix && *addr == ']' && addr[1] == '\0')
+                               break;
                        return FALSE;
+               }
                 addr++;
        }
 
index d6555b5fe9376d002068c0105afd9472807b9bdf..5e6a01d6528bb4048719f902b2e53131e960df32 100644 (file)
@@ -70,7 +70,7 @@ resolve_ip(const char *address, const struct ip_addr **ips_r,
                return 0;
        }
 
-       if (strcmp(address, "::") == 0) {
+       if (strcmp(address, "::") == 0 || strcmp(address, "[::]") == 0) {
                /* IPv6 any */
                ip_list = t_new(struct ip_addr, 1);
                net_get_ip_any6(ip_list);