From c40da92e5b2150dfeb00c21ae79eecde6da7e4c4 Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Mon, 7 Dec 2015 16:09:39 +0900 Subject: [PATCH] Listen on dualstack sockets. Change-Id: Id6eff59c65a7f7e190ab9aa93625e32a9806ae6c --- libcutils/socket_inaddr_any_server.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libcutils/socket_inaddr_any_server.c b/libcutils/socket_inaddr_any_server.c index 7f0ccb8e9..e1b7d842f 100644 --- a/libcutils/socket_inaddr_any_server.c +++ b/libcutils/socket_inaddr_any_server.c @@ -34,21 +34,21 @@ /* open listen() port on any interface */ int socket_inaddr_any_server(int port, int type) { - struct sockaddr_in addr; + struct sockaddr_in6 addr; int s, n; memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = htonl(INADDR_ANY); + addr.sin6_family = AF_INET6; + addr.sin6_port = htons(port); + addr.sin6_addr = in6addr_any; - s = socket(AF_INET, type, 0); - if(s < 0) return -1; + s = socket(AF_INET6, type, 0); + if (s < 0) return -1; n = 1; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &n, sizeof(n)); - if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { close(s); return -1; }