diff options
author | Geoff Garside <geoff@geoffgarside.co.uk> | 2011-06-18 19:21:43 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-07-08 15:57:23 +0200 |
commit | e6bf4c2676cf4e81dea57200310187329d96db49 (patch) | |
tree | 41167d096cdef283aa29e2aa89d380b525b329ea | |
parent | 5be83eecacb8b4a23e1822e81f77d765afbdb7b1 (diff) | |
download | redis-e6bf4c2676cf4e81dea57200310187329d96db49.tar.gz |
Update clusterCommand to handle AF_INET6 addresses
Changes the sockaddr_in to a sockaddr_storage. Attempts to convert the
IP address into an AF_INET or AF_INET6 before returning an "Invalid IP
address" error. Handles converting the sockaddr from either AF_INET or
AF_INET6 back into a string for storage in the clusterNode ip field.
-rw-r--r-- | src/cluster.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cluster.c b/src/cluster.c index 575e46740..f635c389b 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -2075,11 +2075,12 @@ void clusterCommand(redisClient *c) { if (!strcasecmp(c->argv[1]->ptr,"meet") && c->argc == 4) { /* CLUSTER MEET <ip> <port> */ clusterNode *n; - struct sockaddr_in sa; + struct sockaddr_storage sa; long port; /* Perform sanity checks on IP/port */ - if (inet_pton(AF_INET,c->argv[0]->ptr,&(sa.sin_addr)) == 0) { + if ((inet_pton(AF_INET,c->argv[0]->ptr,&(((struct sockaddr_in *)&sa)->sin_addr)) || + inet_pton(AF_INET6,c->argv[0]->ptr,&(((struct sockaddr_in6 *)&sa)->sin6_addr))) == 0) { addReplyError(c,"Invalid IP address in MEET"); return; } @@ -2093,7 +2094,9 @@ void clusterCommand(redisClient *c) { /* Finally add the node to the cluster with a random name, this * will get fixed in the first handshake (ping/pong). */ n = createClusterNode(NULL,REDIS_NODE_HANDSHAKE|REDIS_NODE_MEET); - inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),n->ip,REDIS_CLUSTER_IPLEN); + sa.ss_family == AF_INET ? + inet_ntop(AF_INET,(void*)&(((struct sockaddr_in *)&sa)->sin_addr),n->ip,REDIS_CLUSTER_IPLEN) : + inet_ntop(AF_INET6,(void*)&(((struct sockaddr_in6 *)&sa)->sin6_addr),n->ip,REDIS_CLUSTER_IPLEN); n->port = port; clusterAddNode(n); addReply(c,shared.ok); |