summaryrefslogtreecommitdiff
path: root/libguile/socket.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2004-12-10 00:41:33 +0000
committerKevin Ryde <user42@zip.com.au>2004-12-10 00:41:33 +0000
commit2b4d15471c296cf426f6a54850a0535250f05831 (patch)
tree1bf02eb24350a87dab7697409c9835fa9d93d4c9 /libguile/socket.c
parent66b1c775d20a6c2f317a444dbf1cceb9348c621f (diff)
downloadguile-2b4d15471c296cf426f6a54850a0535250f05831.tar.gz
(scm_from_ipv6): Just use mpz_import. Don't bother trying
to fit scm_from_ulong_long, since that uses mpz_import anyway. Don't bother trying to fit scm_from_ulong, not really worth the trouble if addresses are more than 4 bytes usually.
Diffstat (limited to 'libguile/socket.c')
-rw-r--r--libguile/socket.c69
1 files changed, 10 insertions, 59 deletions
diff --git a/libguile/socket.c b/libguile/socket.c
index 6c4b6531a..743309571 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -278,65 +278,16 @@ SCM_DEFINE (scm_inet_makeaddr, "inet-makeaddr", 2, 0, 0,
static SCM
scm_from_ipv6 (const scm_t_uint8 *src)
{
- int i = 0;
- const scm_t_uint8 *ptr = src;
- int num_zero_bytes = 0;
- scm_t_uint8 addr[16];
-
- /* count leading zeros (since we know it's bigendian, they'll be first) */
- while (i < 16)
- {
- if (*ptr) break;
- num_zero_bytes++;
- i++;
- }
-
- if (SCM_SIZEOF_UNSIGNED_LONG_LONG != 0) /* compiler should optimize this */
- {
- if ((16 - num_zero_bytes) <= sizeof (unsigned long long))
- {
- /* it fits */
- unsigned long long x;
-
- FLIPCPY_NET_HOST_128(addr, src);
-#ifdef WORDS_BIGENDIAN
- memcpy (&x, addr + (16 - sizeof (x)), sizeof (x));
-#else
- memcpy (&x, addr, sizeof (x));
-#endif
- return scm_from_ulong_long (x);
- }
- }
- else
- {
- if ((16 - num_zero_bytes) <= sizeof (unsigned long))
- {
- /* this is just so that we use INUM where possible. */
- unsigned long x;
-
- FLIPCPY_NET_HOST_128(addr, src);
-#ifdef WORDS_BIGENDIAN
- memcpy (&x, addr + (16 - sizeof (x)), sizeof (x));
-#else
- memcpy (&x, addr, sizeof (x));
-#endif
- return scm_from_ulong (x);
- }
- }
- /* otherwise get the big hammer */
- {
- SCM result = scm_i_mkbig ();
-
- mpz_import (SCM_I_BIG_MPZ (result),
- 1, /* chunk */
- 1, /* big-endian chunk ordering */
- 16, /* chunks are 16 bytes long */
- 1, /* big-endian byte ordering */
- 0, /* "nails" -- leading unused bits per chunk */
- src);
- return scm_i_normbig (result);
- }
-}
+ SCM result = scm_i_mkbig ();
+ mpz_import (SCM_I_BIG_MPZ (result),
+ 1, /* chunk */
+ 1, /* big-endian chunk ordering */
+ 16, /* chunks are 16 bytes long */
+ 1, /* big-endian byte ordering */
+ 0, /* "nails" -- leading unused bits per chunk */
+ src);
+ return scm_i_normbig (result);
+}
/* convert a host ordered SCM integer to a 128 bit IPv6 address in
network order. */