Merge "Listen on dualstack sockets."
This commit is contained in:
commit
1f7bcf3e93
1 changed files with 7 additions and 7 deletions
|
@ -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 a new issue