1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Handle IPv4 addresses in inet_ntop.

This commit is contained in:
hniksic 2005-08-09 05:45:45 -07:00
parent 4f8da08d67
commit dd8eafb6c9
2 changed files with 32 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2005-08-09 Hrvoje Niksic <hniksic@xemacs.org>
* mswindows.c (inet_ntop): Also handle IPv4 addresses for
completeness.
2005-08-09 Hrvoje Niksic <hniksic@xemacs.org>
* http.c (gethttp): Don't read more than the amount of data

View File

@ -799,22 +799,39 @@ windows_strerror (int err)
}
#ifdef ENABLE_IPV6
/* An IPv6-only inet_ntop that prints with WSAAddressToString. (Wget
uses inet_ntoa for IPv4 addresses -- see print_address.) Prototype
complies with POSIX 1003.1-2004. */
/* An inet_ntop implementation that uses WSAAddressToString.
Prototype complies with POSIX 1003.1-2004. This is only used under
IPv6 because Wget prints IPv4 addresses using inet_ntoa. */
const char *
inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
{
struct sockaddr_in6 sin6;
/* struct sockaddr can't accomodate struct sockaddr_in6. */
union {
struct sockaddr_in6 sin6;
struct sockaddr_in sin;
} sa;
DWORD dstlen = cnt;
size_t srcsize;
assert (af == AF_INET6);
xzero (sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = *(struct in6_addr *) src;
if (WSAAddressToString ((struct sockaddr *) &sin6, sizeof (sin6),
NULL, dst, &dstlen) != 0)
xzero (sa);
switch (af)
{
case AF_INET:
sa.sin.sin_family = AF_INET;
sa.sin.sin_addr = *(struct in_addr *) src;
srcsize = sizeof (sa.sin);
break;
case AF_INET6:
sa.sin6.sin6_family = AF_INET6;
sa.sin6.sin6_addr = *(struct in6_addr *) src;
srcsize = sizeof (sa.sin6);
break;
default:
abort ();
}
if (WSAAddressToString ((struct sockaddr *) &sa, srcsize, NULL, dst, &dstlen) != 0)
{
errno = WSAGetLastError();
return NULL;