From c45ccdf52fa36f2b9b0590b8ffe33b3dce9c8719 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 22 Nov 2015 16:42:29 +0100 Subject: [PATCH] Only guess port separators for domains requiring it --- src/transport/common.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/transport/common.c b/src/transport/common.c index 7776860..edb3f97 100644 --- a/src/transport/common.c +++ b/src/transport/common.c @@ -21,7 +21,7 @@ static struct addrinfo * _init_address(char const * name, int domain, int flags) struct addrinfo * ai = NULL; char * hostname; char * servname; - char sep = ':'; + char sep; char * p; char * q; long l; @@ -38,9 +38,22 @@ static struct addrinfo * _init_address(char const * name, int domain, int flags) error_set_code(1, "%s", "Empty names are not allowed"); return NULL; } - /* guess the port separator */ - if((p = strchr(name, ':')) != NULL && strchr(++p, ':') != NULL) - sep = '.'; + /* obtain the port separator */ + switch(domain) + { + case AF_INET6: + case AF_UNSPEC: + if((p = strchr(name, ':')) != NULL + && strchr(++p, ':') != NULL) + sep = '.'; + else + sep = ':'; + break; + case AF_INET: + default: + sep = ':'; + break; + } /* obtain the name */ if((p = strdup(name)) == NULL) {