diff options
author | Bruce Momjian <bruce@momjian.us> | 2010-11-24 17:04:19 -0500 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2010-11-24 17:04:19 -0500 |
commit | ba11258ccbf364d85de48b8b7fd46953ea7bb4f4 (patch) | |
tree | 94824222a24f4e98cb2af0e90f845a687eb38dac /src/port/getaddrinfo.c | |
parent | 725d52d0c27cffe8c99bb78e2b0d2480d5cd702b (diff) |
When reporting the server as not responding, if the hostname was
supplied, also print the IP address. This allows IPv4 and IPv6 failures
to be distinguished. Also useful when a hostname resolves to multiple
IP addresses.
Also, remove use of inet_ntoa() and use our own inet_net_ntop() in all
places, including in libpq, because it is thread-safe.
Diffstat (limited to 'src/port/getaddrinfo.c')
-rw-r--r-- | src/port/getaddrinfo.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/port/getaddrinfo.c b/src/port/getaddrinfo.c index f867744eee2..807f5bd56d7 100644 --- a/src/port/getaddrinfo.c +++ b/src/port/getaddrinfo.c @@ -388,16 +388,14 @@ getnameinfo(const struct sockaddr * sa, int salen, if (node) { - int ret = -1; - if (sa->sa_family == AF_INET) { - char *p; - - p = inet_ntoa(((struct sockaddr_in *) sa)->sin_addr); - ret = snprintf(node, nodelen, "%s", p); + if (inet_net_ntop(AF_INET, ((struct sockaddr_in *) sa)->sin_addr, + sa->sa_family == AF_INET ? 32 : 128, + node, nodelen) == NULL) + return EAI_MEMORY; } - if (ret == -1 || ret > nodelen) + else return EAI_MEMORY; } |