From 7a5fb79613d0d5d865d1429432ce124d00e9a6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Tue, 12 Jun 2007 21:55:11 +0000 Subject: [PATCH] Changes from arch/CVS synchronization --- libguile/ChangeLog | 6 ++++++ libguile/socket.c | 22 +++++++++++++++++----- test-suite/ChangeLog | 5 +++++ test-suite/tests/socket.test | 20 ++++++++++++++++++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 5612f1f0e..d97036ac3 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,9 @@ +2007-06-12 Ludovic Courtès + + * socket.c (scm_inet_ntop): In the `AF_INET' case, declare `addr4' + as an `scm_t_uint32' rather than re-using `addr6'. This fixes a + bus error on SPARC (and possibly others) due to unaligned access. + 2007-06-07 Ludovic Courtès * posix.c (scm_ttyname): Check whether RESULT is NULL before diff --git a/libguile/socket.c b/libguile/socket.c index 5d09c615b..4ee8a84e5 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007 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 @@ -386,16 +386,28 @@ SCM_DEFINE (scm_inet_ntop, "inet-ntop", 2, 0, 0, #else char dst[46]; #endif - char addr6[16]; + const char *result; af = scm_to_int (family); SCM_ASSERT_RANGE (1, family, af == AF_INET || af == AF_INET6); if (af == AF_INET) - *(scm_t_uint32 *) addr6 = htonl (SCM_NUM2ULONG (2, address)); + { + scm_t_uint32 addr4; + + addr4 = htonl (SCM_NUM2ULONG (2, address)); + result = inet_ntop (af, &addr4, dst, sizeof (dst)); + } else - scm_to_ipv6 ((scm_t_uint8 *) addr6, address); - if (inet_ntop (af, &addr6, dst, sizeof dst) == NULL) + { + char addr6[16]; + + scm_to_ipv6 ((scm_t_uint8 *) addr6, address); + result = inet_ntop (af, &addr6, dst, sizeof (dst)); + } + + if (result == NULL) SCM_SYSERROR; + return scm_from_locale_string (dst); } #undef FUNC_NAME diff --git a/test-suite/ChangeLog b/test-suite/ChangeLog index 3fcb1a1c8..dbd3fc714 100644 --- a/test-suite/ChangeLog +++ b/test-suite/ChangeLog @@ -1,3 +1,8 @@ +2007-06-12 Ludovic Courtès + + * tests/socket.test: Renamed module to `(test-suite test-socket)'. + (inet-ntop): New test prefix. + 2007-06-07 Ludovic Courtès * lib.scm (exception:system-error): New variable. diff --git a/test-suite/tests/socket.test b/test-suite/tests/socket.test index 7663b56b7..ed8f5fc03 100644 --- a/test-suite/tests/socket.test +++ b/test-suite/tests/socket.test @@ -1,6 +1,6 @@ ;;;; socket.test --- test socket functions -*- scheme -*- ;;;; -;;;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +;;;; Copyright (C) 2004, 2005, 2006, 2007 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 @@ -16,7 +16,7 @@ ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -(define-module (test-suite test-numbers) +(define-module (test-suite test-socket) #:use-module (test-suite lib)) @@ -101,6 +101,22 @@ (inet-pton AF_INET6 "0000:0000:0000:0000:0000:0000:0000:00F0")))))) +(if (defined? 'inet-ntop) + (with-test-prefix "inet-ntop" + + (with-test-prefix "ipv4" + (pass-if "127.0.0.1" + (equal? "127.0.0.1" (inet-ntop AF_INET INADDR_LOOPBACK)))) + + (if (defined? 'AF_INET6) + (with-test-prefix "ipv6" + (pass-if "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF" + (string-ci=? "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF" + (inet-ntop AF_INET6 (- (expt 2 128) 1)))) + + (pass-if "::1" + (equal? "::1" (inet-ntop AF_INET6 1))))))) + ;;; ;;; make-socket-address