summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Garside <geoff@geoffgarside.co.uk>2011-06-18 19:06:26 +0100
committerantirez <antirez@gmail.com>2013-07-08 15:55:39 +0200
commit9cfa02fe734cce966385169427511e8d282fb5a7 (patch)
tree50cfaf3635fe38c2b4b5ca7f165a0a94d02e5656
parent6e894f02cf305ac0e86413e96f51b03571fdbebf (diff)
downloadredis-9cfa02fe734cce966385169427511e8d282fb5a7.tar.gz
Add macro to define clusterNode.ip buffer size.
Add REDIS_CLUSTER_IPLEN macro to define the size of the clusterNode ip character array. Additionally use this macro in inet_ntop(3) calls where the size of the array was being defined manually. The REDIS_CLUSTER_IPLEN is defined as INET_ADDRSTRLEN which defines the correct size of a buffer to store an IPv4 address in. The INET_ADDRSTRLEN macro itself is defined in the <netinet/in.h> header file and should be portable across the majority of systems.
-rw-r--r--src/cluster.c4
-rw-r--r--src/redis.h3
2 files changed, 4 insertions, 3 deletions
diff --git a/src/cluster.c b/src/cluster.c
index e60d82a64..dacddbcc0 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -758,7 +758,7 @@ void nodeIp2String(char *buf, clusterLink *link) {
if (getpeername(link->fd, (struct sockaddr*) &sa, &salen) == -1)
redisPanic("getpeername() failed.");
- inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),buf,16);
+ inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),buf,REDIS_CLUSTER_IPLEN);
}
@@ -2084,7 +2084,7 @@ 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,16);
+ inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),n->ip,REDIS_CLUSTER_IPLEN);
n->port = port;
clusterAddNode(n);
addReply(c,shared.ok);
diff --git a/src/redis.h b/src/redis.h
index e3542967f..2cfcce356 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -120,7 +120,7 @@
#define REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC 1
#define REDIS_DEFAULT_MIN_SLAVES_TO_WRITE 0
#define REDIS_DEFAULT_MIN_SLAVES_MAX_LAG 10
-#define REDIS_IP_STR_LEN 16
+#define REDIS_IP_STR_LEN INET6_ADDRSTRLEN
#define REDIS_BINDADDR_MAX 16
/* Protocol and I/O related defines */
@@ -564,6 +564,7 @@ typedef struct redisOpArray {
#define REDIS_CLUSTER_FAIL 1 /* The cluster can't work */
#define REDIS_CLUSTER_NAMELEN 40 /* sha1 hex length */
#define REDIS_CLUSTER_PORT_INCR 10000 /* Cluster port = baseport + PORT_INCR */
+#define REDIS_CLUSTER_IPLEN INET_ADDRSTRLEN /* IPv4 address string length */
/* The following defines are amunt of time, sometimes expressed as
* multiplicators of the node timeout value (when ending with MULT). */