Server: Call uv_getaddrinfo with NULL service when no port

When using serverstart("ip.ad.d.r:") to listen on a random port, we need
to abide by getaddrinfo()'s API and pass in a NULL service, rather than
an empty string.

When given an empty string, getaddrinfo() is free to search for a
service by the given name (since the string isn't a number) which will
fail.  At least FreeBSD does perform this lookup.
This commit is contained in:
James McCoy
2017-05-27 20:27:33 -04:00
parent 156e6f274f
commit 3f85c2e43a

View File

@@ -45,6 +45,12 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher,
return UV_EINVAL; return UV_EINVAL;
} }
if (*port == NUL) {
// When no port is given, (uv_)getaddrinfo expects NULL otherwise the
// implementation may attempt to lookup the service by name (and fail)
port = NULL;
}
uv_getaddrinfo_t request; uv_getaddrinfo_t request;
int retval = uv_getaddrinfo(&loop->uv, &request, NULL, addr, port, int retval = uv_getaddrinfo(&loop->uv, &request, NULL, addr, port,