summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororanagra <oran@redislabs.com>2016-08-21 20:39:15 +0300
committerantirez <antirez@gmail.com>2016-09-12 10:56:21 +0200
commita6d0698b22e453221403e6aa5733c23897c20c69 (patch)
treec6a9e8ce029fe7b3e53e49c3c6b74c3cc048d1d7
parent22b6c28d25e5df757a46802fdd47061ee319b244 (diff)
downloadredis-a6d0698b22e453221403e6aa5733c23897c20c69.tar.gz
fix tcp binding when IPv6 is unsupported
-rw-r--r--src/anet.c2
-rw-r--r--src/server.c22
2 files changed, 14 insertions, 10 deletions
diff --git a/src/anet.c b/src/anet.c
index 1728f3eb9..ef1711d06 100644
--- a/src/anet.c
+++ b/src/anet.c
@@ -486,7 +486,7 @@ static int _anetTcpServer(char *err, int port, char *bindaddr, int af, int backl
goto end;
}
if (p == NULL) {
- anetSetError(err, "unable to bind socket");
+ anetSetError(err, "unable to bind socket, errno: %d", errno);
goto error;
}
diff --git a/src/server.c b/src/server.c
index d0e8badce..3792b5999 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1776,6 +1776,7 @@ int listenToPort(int port, int *fds, int *count) {
if (server.bindaddr_count == 0) server.bindaddr[0] = NULL;
for (j = 0; j < server.bindaddr_count || j == 0; j++) {
if (server.bindaddr[j] == NULL) {
+ int unsupported = 0;
/* Bind * for both IPv6 and IPv4, we enter here only if
* server.bindaddr_count == 0. */
fds[*count] = anetTcp6Server(server.neterr,port,NULL,
@@ -1783,19 +1784,22 @@ int listenToPort(int port, int *fds, int *count) {
if (fds[*count] != ANET_ERR) {
anetNonBlock(NULL,fds[*count]);
(*count)++;
+ } else if (errno == EAFNOSUPPORT)
+ unsupported++;
- /* Bind the IPv4 address as well. */
- fds[*count] = anetTcpServer(server.neterr,port,NULL,
- server.tcp_backlog);
- if (fds[*count] != ANET_ERR) {
- anetNonBlock(NULL,fds[*count]);
- (*count)++;
- }
- }
+ /* Bind the IPv4 address as well. */
+ fds[*count] = anetTcpServer(server.neterr,port,NULL,
+ server.tcp_backlog);
+ if (fds[*count] != ANET_ERR) {
+ anetNonBlock(NULL,fds[*count]);
+ (*count)++;
+ } else if (errno == EAFNOSUPPORT)
+ unsupported++;
/* Exit the loop if we were able to bind * on IPv4 and IPv6,
+ * or if one is unsupported by th OS.
* otherwise fds[*count] will be ANET_ERR and we'll print an
* error and return to the caller with an error. */
- if (*count == 2) break;
+ if (*count + unsupported == 2) break;
} else if (strchr(server.bindaddr[j],':')) {
/* Bind IPv6 address. */
fds[*count] = anetTcp6Server(server.neterr,port,server.bindaddr[j],