Only guess port separators for domains requiring it

This commit is contained in:
Pierre Pronchery 2015-11-22 16:42:29 +01:00
parent fed91ed241
commit c45ccdf52f

View File

@ -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)
/* 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)
{