summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Garside <geoff@geoffgarside.co.uk>2012-10-17 23:45:44 +0100
committerantirez <antirez@gmail.com>2013-07-08 16:08:36 +0200
commite04fdf26fe929b4f80312f29ead449cf1295c17b (patch)
tree4ac31a379da5b17b323cbec21ae937f36b2ee612
parenta68e3d4c6ae0079c7aed3f11510e50e2dcb8f7cb (diff)
downloadredis-e04fdf26fe929b4f80312f29ead449cf1295c17b.tar.gz
Add IPv6 support to sentinel.c.
This has been done by exposing the anetSockName() function anet.c to be used when the sentinel is publishing its existence to the masters. This implementation is very unintelligent as it will likely break if used with IPv6 as the nested colons will break any parsing of the PUBLISH string by the master.
-rw-r--r--src/anet.h1
-rw-r--r--src/sentinel.c9
2 files changed, 5 insertions, 5 deletions
diff --git a/src/anet.h b/src/anet.h
index ff5897af1..b23411cbb 100644
--- a/src/anet.h
+++ b/src/anet.h
@@ -57,5 +57,6 @@ int anetDisableTcpNoDelay(char *err, int fd);
int anetTcpKeepAlive(char *err, int fd);
int anetPeerToString(int fd, char *ip, size_t ip_len, int *port);
int anetKeepAlive(char *err, int fd, int interval);
+int anetSockName(int fd, char *ip, size_t ip_len, int *port);
#endif
diff --git a/src/sentinel.c b/src/sentinel.c
index cb7008727..e89199fec 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -1837,14 +1837,13 @@ void sentinelPingInstance(sentinelRedisInstance *ri) {
(now - ri->last_pub_time) > SENTINEL_PUBLISH_PERIOD)
{
/* PUBLISH hello messages only to masters. */
- struct sockaddr_in sa;
- socklen_t salen = sizeof(sa);
-
- if (getsockname(ri->cc->c.fd,(struct sockaddr*)&sa,&salen) != -1) {
+ char ip[INET6_ADDRSTRLEN];
+ if (anetSockName(ri->cc->c.fd,ip,sizeof(ip),NULL) != -1) {
char myaddr[128];
+ // FIXME: IPv6 will break this due to nested : characters -geoffgarside
snprintf(myaddr,sizeof(myaddr),"%s:%d:%s:%d",
- inet_ntoa(sa.sin_addr), server.port, server.runid,
+ ip, server.port, server.runid,
(ri->flags & SRI_CAN_FAILOVER) != 0);
retval = redisAsyncCommand(ri->cc,
sentinelPublishReplyCallback, NULL, "PUBLISH %s %s",