From: Marek VavruĊĦa Date: Mon, 27 Apr 2015 14:18:31 +0000 (+0200) Subject: daemon/net: use REUSEADDR and IPV6ONLY for bound sockets X-Git-Tag: v1.0.0-beta1~228^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a2bafc239432a78d69bbc00058a9cddd05dab23;p=thirdparty%2Fknot-resolver.git daemon/net: use REUSEADDR and IPV6ONLY for bound sockets this disables dual-stack and allows binding to both v4 and v4-in-v6 addresses separately --- diff --git a/daemon/io.c b/daemon/io.c index 5597c5a59..6f7e01187 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -70,13 +70,17 @@ void udp_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, int udp_bind(struct endpoint *ep, struct sockaddr *addr) { uv_udp_t *handle = &ep->udp; - int ret = uv_udp_bind(handle, addr, 0); + unsigned flags = UV_UDP_REUSEADDR; + if (addr->sa_family == AF_INET6) { + flags |= UV_UDP_IPV6ONLY; + } + int ret = uv_udp_bind(handle, addr, flags); if (ret != 0) { return ret; } handle->data = NULL; - return uv_udp_recv_start(handle, &handle_getbuf, &udp_recv); + return io_start_read((uv_handle_t *)handle); } void udp_unbind(struct endpoint *ep) @@ -130,7 +134,11 @@ static void tcp_accept(uv_stream_t *master, int status) int tcp_bind(struct endpoint *ep, struct sockaddr *addr) { uv_tcp_t *handle = &ep->tcp; - int ret = uv_tcp_bind(handle, addr, 0); + unsigned flags = UV_UDP_REUSEADDR; + if (addr->sa_family == AF_INET6) { + flags |= UV_UDP_IPV6ONLY; + } + int ret = uv_tcp_bind(handle, addr, flags); if (ret != 0) { return ret; }