Merge "Listen on dualstack sockets." am: 1f7bcf3e93 am: f6df8fce6d

am: 4cb2c1fbb6

* commit '4cb2c1fbb60b5b4684bdd01c140eb82e1c397e3c':
  Listen on dualstack sockets.
This commit is contained in:
Erik Kline 2015-12-08 06:38:12 +00:00 committed by android-build-merger
commit f3501658af

View file

@ -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;
}