Use Gnulib's `inet_ntop' and `inet_pton' modules.
[bpt/guile.git] / libguile / socket.c
index d463d04..4f4d392 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -27,7 +27,7 @@
 #include <gmp.h>
 
 #include "libguile/_scm.h"
-#include "libguile/unif.h"
+#include "libguile/arrays.h"
 #include "libguile/feature.h"
 #include "libguile/fports.h"
 #include "libguile/strings.h"
@@ -349,10 +349,9 @@ scm_to_ipv6 (scm_t_uint8 dst[16], SCM src)
       scm_remember_upto_here_1 (src);
     }
   else
-    scm_wrong_type_arg (NULL, 0, src);
+    scm_wrong_type_arg_msg ("scm_to_ipv6", 0, src, "integer");
 }
 
-#ifdef HAVE_INET_PTON
 SCM_DEFINE (scm_inet_pton, "inet-pton", 2, 0, 0,
             (SCM family, SCM address),
            "Convert a string containing a printable network address to\n"
@@ -388,9 +387,7 @@ SCM_DEFINE (scm_inet_pton, "inet-pton", 2, 0, 0,
     return scm_from_ipv6 ((scm_t_uint8 *) dst);
 }
 #undef FUNC_NAME
-#endif
 
-#ifdef HAVE_INET_NTOP
 SCM_DEFINE (scm_inet_ntop, "inet-ntop", 2, 0, 0,
             (SCM family, SCM address),
            "Convert a network address into a printable string.\n"
@@ -399,8 +396,8 @@ SCM_DEFINE (scm_inet_ntop, "inet-ntop", 2, 0, 0,
            "@var{family} can be @code{AF_INET} or @code{AF_INET6}.  E.g.,\n\n"
            "@lisp\n"
            "(inet-ntop AF_INET 2130706433) @result{} \"127.0.0.1\"\n"
-           "(inet-ntop AF_INET6 (- (expt 2 128) 1)) @result{}\n"
-           "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff\n"
+           "(inet-ntop AF_INET6 (- (expt 2 128) 1))\n"
+           "  @result{} \"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff\"\n"
            "@end lisp")
 #define FUNC_NAME s_scm_inet_ntop
 {
@@ -435,7 +432,6 @@ SCM_DEFINE (scm_inet_ntop, "inet-ntop", 2, 0, 0,
   return scm_from_locale_string (dst);
 }
 #undef FUNC_NAME
-#endif
 
 #endif  /* HAVE_IPV6 */
 
@@ -1169,7 +1165,8 @@ scm_to_sockaddr (SCM address, size_t *address_size)
          {
            struct sockaddr_in6 c_inet6;
 
-           scm_to_ipv6 (c_inet6.sin6_addr.s6_addr, address);
+           scm_to_ipv6 (c_inet6.sin6_addr.s6_addr,
+                        SCM_SIMPLE_VECTOR_REF (address, 1));
            c_inet6.sin6_port =
              htons (scm_to_ushort (SCM_SIMPLE_VECTOR_REF (address, 2)));
            c_inet6.sin6_flowinfo =