]> sjero.net Git - wget/commitdiff
[svn] Implement inet_ntop on Windows.
authorhniksic <devnull@localhost>
Thu, 30 Jun 2005 13:48:10 +0000 (06:48 -0700)
committerhniksic <devnull@localhost>
Thu, 30 Jun 2005 13:48:10 +0000 (06:48 -0700)
src/ChangeLog
src/host.c
src/mswindows.c
src/mswindows.h

index ee4ebffd2c686b6a5e66c524395be7bebd8a8a47..95c48edcff4f3bfdb8dda0cfa7ec1503a12c5af2 100644 (file)
@@ -1,3 +1,13 @@
+2005-06-30  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * host.c (pretty_print_address): Handle error result from
+       inet_ntop.
+
+2005-06-30  Gisle Vanem  <giva@bgnett.no>
+
+       * mswindows.c (inet_ntop): New function.  Print IPv6 addresses
+       using WSAAddressToString.
+
 2005-06-27  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * progress.c (dot_update): Remove unused variable row_qty.
index 6bf6514aedc50e4b1cb4170560f6bde09fd0d6fe..46dfee8d246f3955263ad4d4105991a43ffc73f1 100644 (file)
@@ -418,18 +418,10 @@ pretty_print_address (const ip_address *addr)
 #ifdef ENABLE_IPV6
     case IPV6_ADDRESS:
       {
-        static char buf[128];
-       inet_ntop (AF_INET6, &ADDRESS_IPV6_IN6_ADDR (addr), buf, sizeof (buf));
-#if 0
-#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
-       {
-         /* append "%SCOPE_ID" for all ?non-global? addresses */
-         char *p = buf + strlen (buf);
-         *p++ = '%';
-         number_to_string (p, ADDRESS_IPV6_SCOPE (addr));
-       }
-#endif
-#endif
+        static char buf[64];
+       if (!inet_ntop (AF_INET6, &ADDRESS_IPV6_IN6_ADDR (addr),
+                       buf, sizeof (buf)))
+         snprintf (buf, sizeof buf, "[error: %s]", strerror (errno));
         buf[sizeof (buf) - 1] = '\0';
         return buf;
       }
index e61e9b8df9a0dd9e12ffa432176a79e5869b69b7..2890274bc982e215fb4dd866d4ce5415d461b2e3 100644 (file)
@@ -848,3 +848,28 @@ windows_strerror (int err)
       return buf;
     }
 }
+\f
+#ifdef ENABLE_IPV6
+/* An IPv6-only inet_ntop that prints with WSAAddressToString.  (Wget
+   uses inet_ntoa for IPv4 addresses -- see pretty_print_address.)
+   Prototype complies with POSIX 1003.1-2004.  */
+
+const char *
+inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
+{
+  struct sockaddr_in6 sin6;
+  DWORD dstlen = cnt;
+
+  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)
+    {
+      errno = WSAGetLastError();
+      return NULL;
+    }
+  return (const char *) dst;
+}
+#endif
index fbf04ff29842d9ec2e65392a53ea6a45ecc20872..15edcf0d1c6d56a47ed3b15519493beaa4b06e69 100644 (file)
@@ -134,8 +134,7 @@ __int64 str_to_int64 (const char *, char **, int);
 
 /* Additional declarations needed for IPv6: */
 #ifdef ENABLE_IPV6
-/* Missing declaration? */
-extern const char *inet_ntop (int, const void *, char *, size_t);
+const char *inet_ntop (int, const void *, char *, socklen_t);
 /* MinGW 3.7 (or older) prototypes gai_strerror(), but is missing
    from all import libraries. */
 # ifdef __MINGW32__