Listen on dualstack sockets.
Change-Id: Id6eff59c65a7f7e190ab9aa93625e32a9806ae6c
This commit is contained in:
parent
7e16cc15b5
commit
c40da92e5b
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue