summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anet.c17
-rw-r--r--src/anet.h1
2 files changed, 16 insertions, 2 deletions
diff --git a/src/anet.c b/src/anet.c
index bbefa2fe9..434d8311e 100644
--- a/src/anet.c
+++ b/src/anet.c
@@ -372,7 +372,7 @@ static int anetV6Only(char *err, int s) {
return ANET_OK;
}
-int anetTcpServer(char *err, int port, char *bindaddr)
+static int _anetTcpServer(char *err, int port, char *bindaddr, int af)
{
int s, rv;
char _port[6]; /* strlen("65535") */
@@ -380,7 +380,7 @@ int anetTcpServer(char *err, int port, char *bindaddr)
snprintf(_port,6,"%d",port);
memset(&hints,0,sizeof(hints));
- hints.ai_family = AF_INET;
+ hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; /* No effect if bindaddr != NULL */
@@ -392,6 +392,9 @@ int anetTcpServer(char *err, int port, char *bindaddr)
if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
continue;
+ if (AF_INET6 == af && anetV6Only(err,s) == ANET_ERR)
+ goto error; /* could continue here? */
+
if (anetListen(err,s,p->ai_addr,p->ai_addrlen) == ANET_ERR)
goto error; /* could continue here? */
goto end;
@@ -408,6 +411,16 @@ end:
return s;
}
+int anetTcpServer(char *err, int port, char *bindaddr)
+{
+ return _anetTcpServer(err, port, bindaddr, AF_INET);
+}
+
+int anetTcp6Server(char *err, int port, char *bindaddr)
+{
+ return _anetTcpServer(err, port, bindaddr, AF_INET6);
+}
+
int anetUnixServer(char *err, char *path, mode_t perm)
{
int s;
diff --git a/src/anet.h b/src/anet.h
index ccc67c634..ff5897af1 100644
--- a/src/anet.h
+++ b/src/anet.h
@@ -46,6 +46,7 @@ int anetUnixNonBlockConnect(char *err, char *path);
int anetRead(int fd, char *buf, int count);
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len);
int anetTcpServer(char *err, int port, char *bindaddr);
+int anetTcp6Server(char *err, int port, char *bindaddr);
int anetUnixServer(char *err, char *path, mode_t perm);
int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port);
int anetUnixAccept(char *err, int serversock);