diff --git a/common.c b/common.c index cc85bb1..810a610 100644 --- a/common.c +++ b/common.c @@ -442,16 +442,31 @@ char* sprintaddr(char* buf, size_t size, struct addrinfo *a) /* Turns a hostname and port (or service) into a list of struct addrinfo * returns 0 on success, -1 otherwise and logs error + * + * *host gets modified **/ -int resolve_split_name(struct addrinfo **out, const char* host, const char* serv) +int resolve_split_name(struct addrinfo **out, char* host, const char* serv) { struct addrinfo hint; + char *end; int res; memset(&hint, 0, sizeof(hint)); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; + /* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets + * around IP address */ + if (host[0] == '[') { + end = strrchr(host, ']'); + if (!end) { + fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host); + } + host++; /* skip first bracket */ + *end = 0; /* remove last bracket */ + } + + res = getaddrinfo(host, serv, &hint, out); if (res) log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv); @@ -464,7 +479,7 @@ fullname: input string -- it gets clobbered */ void resolve_name(struct addrinfo **out, char* fullname) { - char *serv, *host, *end; + char *serv, *host; int res; /* Find port */ @@ -478,17 +493,6 @@ void resolve_name(struct addrinfo **out, char* fullname) host = fullname; - /* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets - * around IP address */ - if (host[0] == '[') { - end = strrchr(host, ']'); - if (!end) { - fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host); - } - host++; /* skip first bracket */ - *end = 0; /* remove last bracket */ - } - res = resolve_split_name(out, host, serv); if (res) { fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname); diff --git a/common.h b/common.h index 701b337..c83eb91 100644 --- a/common.h +++ b/common.h @@ -106,7 +106,7 @@ void drop_privileges(const char* user_name); void write_pid_file(const char* pidfile); void log_message(int type, char* msg, ...); void dump_connection(struct connection *cnx); -int resolve_split_name(struct addrinfo **out, const char* hostname, const char* port); +int resolve_split_name(struct addrinfo **out, char* hostname, const char* port); int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);