mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Update anetResolve to resolve AF_INET6 as well.
Change the getaddrinfo(3) hints family from AF_INET to AF_UNSPEC to allow resolution of IPv6 addresses as well as IPv4 addresses. The function will return the IP address of whichever address family is preferenced by the operating system. Most current operating systems will preference AF_INET6 over AF_INET. Unfortunately without attempting to establish a connection to the remote address we can't know if the host is capable of using the returned IP address. It might be desirable to have anetResolve accept an additional argument specifying the AF_INET/AF_INET6 address the caller would like to receive. Currently though it does not appear as though the anetResolve function is ever used within Redis.
This commit is contained in:
parent
2345cee335
commit
e7b34e8dc3
10
src/anet.c
10
src/anet.c
@ -166,11 +166,11 @@ int anetTcpKeepAlive(char *err, int fd)
|
|||||||
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len)
|
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len)
|
||||||
{
|
{
|
||||||
struct addrinfo hints, *info;
|
struct addrinfo hints, *info;
|
||||||
void *addr;
|
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
memset(&hints,0,sizeof(hints));
|
memset(&hints,0,sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM; /* specify socktype to avoid dups */
|
||||||
|
|
||||||
if ((rv = getaddrinfo(host, NULL, &hints, &info)) != 0) {
|
if ((rv = getaddrinfo(host, NULL, &hints, &info)) != 0) {
|
||||||
anetSetError(err, "%s", gai_strerror(rv));
|
anetSetError(err, "%s", gai_strerror(rv));
|
||||||
@ -178,10 +178,12 @@ int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len)
|
|||||||
}
|
}
|
||||||
if (info->ai_family == AF_INET) {
|
if (info->ai_family == AF_INET) {
|
||||||
struct sockaddr_in *sa = (struct sockaddr_in *)info->ai_addr;
|
struct sockaddr_in *sa = (struct sockaddr_in *)info->ai_addr;
|
||||||
addr = &(sa->sin_addr);
|
inet_ntop(AF_INET, &(sa->sin_addr), ipbuf, ipbuf_len);
|
||||||
|
} else {
|
||||||
|
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)info->ai_addr;
|
||||||
|
inet_ntop(AF_INET6, &(sa->sin6_addr), ipbuf, ipbuf_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
inet_ntop(info->ai_family, addr, ipbuf, ipbuf_len);
|
|
||||||
freeaddrinfo(info);
|
freeaddrinfo(info);
|
||||||
return ANET_OK;
|
return ANET_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user