diff options
Diffstat (limited to 'lib/roken/inet_ntop.c')
| -rw-r--r-- | lib/roken/inet_ntop.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/roken/inet_ntop.c b/lib/roken/inet_ntop.c index 7433c3725e28..b3c327cc3e58 100644 --- a/lib/roken/inet_ntop.c +++ b/lib/roken/inet_ntop.c @@ -1,23 +1,23 @@ /* - * Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan + * Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * 3. Neither the name of the Institute nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -31,10 +31,7 @@ * SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H #include <config.h> -RCSID("$Id: inet_ntop.c 21005 2007-06-08 01:54:35Z lha $"); -#endif #include "roken.h" @@ -86,6 +83,7 @@ inet_ntop_v6 (const void *src, char *dst, size_t size) const struct in6_addr *addr = (struct in6_addr *)src; const u_char *ptr = addr->s6_addr; const char *orig_dst = dst; + int compressed = 0; if (size < INET6_ADDRSTRLEN) { errno = ENOSPC; @@ -94,6 +92,26 @@ inet_ntop_v6 (const void *src, char *dst, size_t size) for (i = 0; i < 8; ++i) { int non_zerop = 0; + if (compressed == 0 && + ptr[0] == 0 && ptr[1] == 0 && + i <= 5 && + ptr[2] == 0 && ptr[3] == 0 && + ptr[4] == 0 && ptr[5] == 0) { + + compressed = 1; + + if (i == 0) + *dst++ = ':'; + *dst++ = ':'; + + for (ptr += 6, i += 3; + i < 8 && ptr[0] == 0 && ptr[1] == 0; + ++i, ptr += 2); + + if (i >= 8) + break; + } + if (non_zerop || (ptr[0] >> 4)) { *dst++ = xdigits[ptr[0] >> 4]; non_zerop = 1; @@ -116,7 +134,7 @@ inet_ntop_v6 (const void *src, char *dst, size_t size) } #endif /* HAVE_IPV6 */ -const char * ROKEN_LIB_FUNCTION +ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL inet_ntop(int af, const void *src, char *dst, size_t size) { switch (af) { |
