summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 911198f)
raw | patch | inline | side by side (parent: 911198f)
author | Benjamin Kramer <benny.kra@googlemail.com> | |
Fri, 24 Apr 2009 12:16:41 +0000 (14:16 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 25 Apr 2009 16:29:38 +0000 (09:29 -0700) |
inet_ntop is not protocol independent.
getnameinfo(3) is part of POSIX and is available when getaddrinfo(3) is.
This code is only compiled when NO_IPV6 isn't defined.
The old method was buggy anyway, not every ipv6 address was converted
properly because the buffer (addr) was too small.
Signed-off-by: Benjamin Kramer <benny.kra@googlemail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
getnameinfo(3) is part of POSIX and is available when getaddrinfo(3) is.
This code is only compiled when NO_IPV6 isn't defined.
The old method was buggy anyway, not every ipv6 address was converted
properly because the buffer (addr) was too small.
Signed-off-by: Benjamin Kramer <benny.kra@googlemail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
connect.c | patch | blob | history |
diff --git a/connect.c b/connect.c
index 7636bf976e78a6622281501af2dcc0135781f60a..f6b8ba6fec16ed2ff2de4c66e2465e79d059a817 100644 (file)
--- a/connect.c
+++ b/connect.c
static const char *ai_name(const struct addrinfo *ai)
{
- static char addr[INET_ADDRSTRLEN];
- if ( AF_INET == ai->ai_family ) {
- struct sockaddr_in *in;
- in = (struct sockaddr_in *)ai->ai_addr;
- inet_ntop(ai->ai_family, &in->sin_addr, addr, sizeof(addr));
- } else if ( AF_INET6 == ai->ai_family ) {
- struct sockaddr_in6 *in;
- in = (struct sockaddr_in6 *)ai->ai_addr;
- inet_ntop(ai->ai_family, &in->sin6_addr, addr, sizeof(addr));
- } else {
+ static char addr[NI_MAXHOST];
+ if (getnameinfo(ai->ai_addr, ai->ai_addrlen, addr, sizeof(addr), NULL, 0,
+ NI_NUMERICHOST) != 0)
strcpy(addr, "(unknown)");
- }
+
return addr;
}