mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Update node2IpString to handle AF_INET6 addresses.
Change the sockaddr_in to sockaddr_storage which is capable of storing both AF_INET and AF_INET6 sockets. Uses the sockaddr_storage ss_family to correctly return the printable IP address and port. Function makes the assumption that the buffer is of at least REDIS_CLUSTER_IPLEN bytes in size.
This commit is contained in:
parent
6181455ac6
commit
5be83eecac
@ -753,14 +753,21 @@ void clusterProcessGossipSection(clusterMsg *hdr, clusterLink *link) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IP -> string conversion. 'buf' is supposed to at least be 16 bytes. */
|
/* IP -> string conversion. 'buf' is supposed to at least be 46 bytes. */
|
||||||
void nodeIp2String(char *buf, clusterLink *link) {
|
void nodeIp2String(char *buf, clusterLink *link) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_storage sa;
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
|
|
||||||
if (getpeername(link->fd, (struct sockaddr*) &sa, &salen) == -1)
|
if (getpeername(link->fd, (struct sockaddr*) &sa, &salen) == -1)
|
||||||
redisPanic("getpeername() failed.");
|
redisPanic("getpeername() failed.");
|
||||||
inet_ntop(sa.sin_family,(void*)&(sa.sin_addr),buf,REDIS_CLUSTER_IPLEN);
|
|
||||||
|
if (sa.ss_family == AF_INET) {
|
||||||
|
struct sockaddr_in *s = (struct sockaddr_in *)&sa;
|
||||||
|
inet_ntop(AF_INET,(void*)&(s->sin_addr),buf,REDIS_CLUSTER_IPLEN);
|
||||||
|
} else {
|
||||||
|
struct sockaddr_in6 *s = (struct sockaddr_in6 *)&sa;
|
||||||
|
inet_ntop(AF_INET6,(void*)&(s->sin6_addr),buf,REDIS_CLUSTER_IPLEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user