diff -pruN /home/reed/src/isc/libbind/libbind/inet/_inet_aton.c /usr/src/lib/libc/inet/_inet_aton.c --- /home/reed/src/isc/libbind/libbind/inet/_inet_aton.c 1969-12-31 18:00:00.000000000 -0600 +++ /usr/src/lib/libc/inet/_inet_aton.c 2005-09-12 20:44:09.000000000 -0500 @@ -0,0 +1,29 @@ +/* $NetBSD: _inet_aton.c,v 1.4 2005/09/13 01:44:09 christos Exp $ */ + +/* + * Written by Klaus Klein, September 14, 1999. + * Public domain. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: _inet_aton.c,v 1.4 2005/09/13 01:44:09 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#if defined(__indr_reference) +__indr_reference(_inet_aton, inet_aton) +#else + +#include +#include +#include + +int _inet_aton(const char *, struct in_addr *); + +int +inet_aton(const char *cp, struct in_addr *addr) +{ + + return _inet_aton(cp, addr); +} +#endif diff -pruN /home/reed/src/isc/libbind/libbind/inet/_inet_pton.c /usr/src/lib/libc/inet/_inet_pton.c --- /home/reed/src/isc/libbind/libbind/inet/_inet_pton.c 1969-12-31 18:00:00.000000000 -0600 +++ /usr/src/lib/libc/inet/_inet_pton.c 2005-09-12 20:44:09.000000000 -0500 @@ -0,0 +1,29 @@ +/* $NetBSD: _inet_pton.c,v 1.4 2005/09/13 01:44:09 christos Exp $ */ + +/* + * Written by Klaus Klein, September 14, 1999. + * Public domain. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: _inet_pton.c,v 1.4 2005/09/13 01:44:09 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#if defined(__indr_reference) +__indr_reference(_inet_pton, inet_pton) +#else + +#include +#include +#include + +int _inet_pton(int, const char *, void *); + +int +inet_pton(int af, const char *src, void *dst) +{ + + return _inet_pton(af, src, dst); +} +#endif diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_cidr_ntop.c /usr/src/lib/libc/inet/inet_cidr_ntop.c --- /home/reed/src/isc/libbind/libbind/inet/inet_cidr_ntop.c 2006-10-10 21:18:18.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_cidr_ntop.c 2013-06-05 09:26:10.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_cidr_ntop.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. @@ -15,18 +17,25 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 1.7 2006/10/11 02:18:18 marka Exp $"; +#if 0 +static const char rcsid[] = "Id: inet_cidr_ntop.c,v 1.7 2006/10/11 02:18:18 marka Exp"; +#else +__RCSID("$NetBSD: inet_cidr_ntop.c,v 1.8 2012/03/13 21:13:38 christos Exp $"); +#endif #endif #include "port_before.h" +#include "namespace.h" #include #include #include #include #include +#include #include #include #include @@ -34,6 +43,10 @@ static const char rcsid[] = "$Id: inet_c #include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_cidr_ntop,_inet_cidr_ntop) +#endif + #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else @@ -73,10 +86,10 @@ inet_cidr_ntop(int af, const void *src, } static int -decoct(const u_char *src, int bytes, char *dst, size_t size) { +decoct(const u_char *src, size_t bytes, char *dst, size_t size) { char *odst = dst; char *t; - int b; + size_t b; for (b = 1; b <= bytes; b++) { if (size < sizeof "255.") @@ -89,7 +102,8 @@ decoct(const u_char *src, int bytes, cha } size -= (size_t)(dst - t); } - return (dst - odst); + _DIAGASSERT(__type_fit(int, dst - odst)); + return (int)(dst - odst); } /*% @@ -221,7 +235,7 @@ inet_cidr_ntop_ipv6(const u_char *src, i if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { - int n; + size_t n; if (src[15] || bits == -1 || bits > 120) n = 4; diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_cidr_pton.c /usr/src/lib/libc/inet/inet_cidr_pton.c --- /home/reed/src/isc/libbind/libbind/inet/inet_cidr_pton.c 2005-04-26 23:56:19.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_cidr_pton.c 2013-06-05 09:26:10.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_cidr_pton.c,v 1.8 2012/03/20 17:08:13 matt Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. @@ -15,12 +17,18 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_cidr_pton.c,v 1.6 2005/04/27 04:56:19 sra Exp $"; +#if 0 +static const char rcsid[] = "Id: inet_cidr_pton.c,v 1.6 2005/04/27 04:56:19 sra Exp"; +#else +__RCSID("$NetBSD: inet_cidr_pton.c,v 1.8 2012/03/20 17:08:13 matt Exp $"); +#endif #endif #include "port_before.h" +#include "namespace.h" #include #include #include @@ -32,6 +40,7 @@ static const char rcsid[] = "$Id: inet_c #include #include #include +#include #include #include "port_after.h" @@ -42,10 +51,13 @@ static const char rcsid[] = "$Id: inet_c # define SPRINTF(x) ((size_t)sprintf x) #endif -static int inet_cidr_pton_ipv4 __P((const char *src, u_char *dst, - int *bits, int ipv6)); -static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, - int *bits)); +#ifdef __weak_alias +__weak_alias(inet_cidr_pton,_inet_cidr_pton) +#endif + +static int inet_cidr_pton_ipv4(const char *src, u_char *dst, + int *bits, int ipv6); +static int inet_cidr_pton_ipv6(const char *src, u_char *dst, int *bits); static int getbits(const char *, int ipv6); @@ -84,7 +96,8 @@ static const char digits[] = "0123456789 static int inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { const u_char *odst = dst; - int n, ch, tmp, bits; + int ch, bits; + ptrdiff_t n, tmp; size_t size = 4; /* Get the mantissa. */ @@ -176,7 +189,7 @@ inet_cidr_pton_ipv6(const char *src, u_c pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (val > 0xffff) return (0); saw_xdigit = 1; @@ -225,7 +238,7 @@ inet_cidr_pton_ipv6(const char *src, u_c * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) @@ -264,7 +277,7 @@ getbits(const char *src, int ipv6) { if (cp == NULL) /*%< syntax */ return (-2); bits *= 10; - bits += cp - digits; + bits += (int)(cp - digits); if (bits == 0 && *src != '\0') /*%< no leading zeros */ return (-2); if (bits > (ipv6 ? 128 : 32)) /*%< range error */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_data.c /usr/src/lib/libc/inet/inet_data.c --- /home/reed/src/isc/libbind/libbind/inet/inet_data.c 2005-04-26 23:56:19.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_data.c 1969-12-31 18:00:00.000000000 -0600 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1995-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id: inet_data.c,v 1.4 2005/04/27 04:56:19 sra Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include "port_before.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "port_after.h" - -const struct in6_addr isc_in6addr_any = IN6ADDR_ANY_INIT; -const struct in6_addr isc_in6addr_loopback = IN6ADDR_LOOPBACK_INIT; - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_lnaof.c /usr/src/lib/libc/inet/inet_lnaof.c --- /home/reed/src/isc/libbind/libbind/inet/inet_lnaof.c 2013-04-04 17:43:29.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_lnaof.c 2004-05-20 18:13:02.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_lnaof.c,v 1.1 2004/05/20 23:13:02 christos Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -27,28 +29,33 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; +#if 0 +static char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: inet_lnaof.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ -#include "port_before.h" - +#include "namespace.h" #include #include #include -#include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_lnaof,_inet_lnaof) +#endif -/*% +/* * Return the local network address portion of an * internet address; handles class a/b/c network * number formats. */ -u_long -inet_lnaof(in) - struct in_addr in; +in_addr_t +inet_lnaof(struct in_addr in) { - register u_long i = ntohl(in.s_addr); + in_addr_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return ((i)&IN_CLASSA_HOST); @@ -57,5 +64,3 @@ inet_lnaof(in) else return ((i)&IN_CLASSC_HOST); } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_makeaddr.c /usr/src/lib/libc/inet/inet_makeaddr.c --- /home/reed/src/isc/libbind/libbind/inet/inet_makeaddr.c 2013-04-04 17:43:29.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_makeaddr.c 2004-05-20 18:13:02.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_makeaddr.c,v 1.1 2004/05/20 23:13:02 christos Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -27,38 +29,42 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; +#if 0 +static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: inet_makeaddr.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ -#include "port_before.h" - +#include "namespace.h" #include #include #include -#include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_makeaddr,_inet_makeaddr) +#endif -/*% +/* * Formulate an Internet address from network + host. Used in * building addresses stored in the ifnet structure. */ struct in_addr -inet_makeaddr(net, host) - u_long net, host; +inet_makeaddr(in_addr_t net, in_addr_t host) { - struct in_addr a; + in_addr_t addr; + struct in_addr ret; - if (net < 128U) - a.s_addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536U) - a.s_addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + if (net < 128) + addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536) + addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); else if (net < 16777216L) - a.s_addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); else - a.s_addr = net | host; - a.s_addr = htonl(a.s_addr); - return (a); + addr = net | host; + ret.s_addr = htonl(addr); + return ret; } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_net_ntop.c /usr/src/lib/libc/inet/inet_net_ntop.c --- /home/reed/src/isc/libbind/libbind/inet/inet_net_ntop.c 2006-06-19 21:50:14.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_net_ntop.c 2013-06-05 09:26:10.000000000 -0500 @@ -1,26 +1,32 @@ /* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.5 2006/06/20 02:50:14 marka Exp $"; +#ifdef notdef +static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.1 2002/08/02 02:17:21 marka Exp "; +#else +__RCSID("$NetBSD: inet_net_ntop.c,v 1.3 2012/03/20 17:08:13 matt Exp $"); +#endif #endif #include "port_before.h" +#include "namespace.h" #include #include #include @@ -33,18 +39,22 @@ static const char rcsid[] = "$Id: inet_n #include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_net_ntop,_inet_net_ntop) +#endif + #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) sprintf x #endif -static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, - char *dst, size_t size)); -static char * inet_net_ntop_ipv6 __P((const u_char *src, int bits, - char *dst, size_t size)); +static char * inet_net_ntop_ipv4(const u_char *src, int bits, + char *dst, size_t size); +static char * inet_net_ntop_ipv6(const u_char *src, int bits, + char *dst, size_t size); -/*% +/* * char * * inet_net_ntop(af, src, bits, dst, size) * convert network number from network to presentation format. @@ -55,12 +65,7 @@ static char * inet_net_ntop_ipv6 __P((co * Paul Vixie (ISC), July 1996 */ char * -inet_net_ntop(af, src, bits, dst, size) - int af; - const void *src; - int bits; - char *dst; - size_t size; +inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { case AF_INET: @@ -73,7 +78,7 @@ inet_net_ntop(af, src, bits, dst, size) } } -/*% +/* * static char * * inet_net_ntop_ipv4(src, bits, dst, size) * convert IPv4 network number from network to presentation format. @@ -87,11 +92,7 @@ inet_net_ntop(af, src, bits, dst, size) * Paul Vixie (ISC), July 1996 */ static char * -inet_net_ntop_ipv4(src, bits, dst, size) - const u_char *src; - int bits; - char *dst; - size_t size; +inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { char *odst = dst; char *t; @@ -148,7 +149,7 @@ inet_net_ntop_ipv4(src, bits, dst, size) return (NULL); } -/*% +/* * static char * * inet_net_ntop_ipv6(src, bits, fakebits, dst, size) * convert IPv6 network number from network to presentation format. @@ -166,17 +167,18 @@ inet_net_ntop_ipv4(src, bits, dst, size) */ static char * -inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { +inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) +{ u_int m; int b; - int p; - int zero_s, zero_l, tmp_zero_s, tmp_zero_l; - int i; + size_t p; + size_t zero_s, zero_l, tmp_zero_s, tmp_zero_l; + size_t i; int is_ipv4 = 0; unsigned char inbuf[16]; char outbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")]; char *cp; - int words; + size_t words; u_char *s; if (bits < 0 || bits > 128) { @@ -264,7 +266,7 @@ inet_net_ntop_ipv6(const u_char *src, in } } /* Format CIDR /width. */ - sprintf(cp, "/%u", bits); + (void)SPRINTF((cp, "/%u", bits)); if (strlen(outbuf) + 1 > size) goto emsgsize; strcpy(dst, outbuf); @@ -275,5 +277,3 @@ emsgsize: errno = EMSGSIZE; return (NULL); } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_net_pton.c /usr/src/lib/libc/inet/inet_net_pton.c --- /home/reed/src/isc/libbind/libbind/inet/inet_net_pton.c 2008-11-13 20:36:51.000000000 -0600 +++ /usr/src/lib/libc/inet/inet_net_pton.c 2013-06-05 09:26:10.000000000 -0500 @@ -1,26 +1,32 @@ /* - * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") - * Copyright (C) 1996, 1998, 1999, 2001, 2003 Internet Software Consortium. + * Copyright (c) 1996,1999 by Internet Software Consortium. * - * Permission to use, copy, modify, and/or distribute this software for any + * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_pton.c,v 1.10 2008/11/14 02:36:51 marka Exp $"; +#if 0 +static const char rcsid[] = "Id: inet_net_pton.c,v 1.4.2.1 2002/08/02 02:17:21 marka Exp "; +#else +__RCSID("$NetBSD: inet_net_pton.c,v 1.4 2012/03/20 17:08:13 matt Exp $"); +#endif #endif #include "port_before.h" +#include "namespace.h" #include #include #include @@ -28,6 +34,7 @@ static const char rcsid[] = "$Id: inet_n #include #include +#include #include #include #include @@ -36,13 +43,18 @@ static const char rcsid[] = "$Id: inet_n #include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_net_pton,_inet_net_pton) +#endif + #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif -/*% + +/* * static int * inet_net_pton_ipv4(src, dst, size) * convert IPv4 network number from presentation to network format. @@ -59,24 +71,28 @@ static const char rcsid[] = "$Id: inet_n * Paul Vixie (ISC), June 1996 */ static int -inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) { +inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) +{ static const char xdigits[] = "0123456789abcdef"; static const char digits[] = "0123456789"; - int n, ch, tmp = 0, dirty, bits; + int ch, dirty, bits; + ptrdiff_t n, tmp; const u_char *odst = dst; + tmp = 0; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii((unsigned char)(src[1])) - && isxdigit((unsigned char)(src[1]))) { + && isascii((u_char)(src[1])) + && isxdigit((u_char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ - if (size <= 0U) + if (size == 0) goto emsgsize; dirty = 0; - src++; /*%< skip x or X. */ - while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); + src++; /* skip x or X. */ + while ((ch = *src++) != '\0' && isascii((u_char)ch) + && isxdigit((u_char)ch)) { + if (isupper((u_char)ch)) + ch = tolower((u_char)ch); n = strchr(xdigits, ch) - xdigits; INSIST(n >= 0 && n <= 15); if (dirty == 0) @@ -84,18 +100,18 @@ inet_net_pton_ipv4(const char *src, u_ch else tmp = (tmp << 4) | n; if (++dirty == 2) { - if (size-- <= 0U) + if (size-- == 0) goto emsgsize; *dst++ = (u_char) tmp; dirty = 0; } } - if (dirty) { /*%< Odd trailing nybble? */ - if (size-- <= 0U) + if (dirty) { /* Odd trailing nybble? */ + if (size-- == 0) goto emsgsize; *dst++ = (u_char) (tmp << 4); } - } else if (isascii(ch) && isdigit(ch)) { + } else if (isascii((u_char)ch) && isdigit((u_char)ch)) { /* Decimal: eat dotted digit string. */ for (;;) { tmp = 0; @@ -107,8 +123,8 @@ inet_net_pton_ipv4(const char *src, u_ch if (tmp > 255) goto enoent; } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (size-- <= 0U) + isascii((u_char)ch) && isdigit((u_char)ch)); + if (size-- == 0) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') @@ -116,26 +132,27 @@ inet_net_pton_ipv4(const char *src, u_ch if (ch != '.') goto enoent; ch = *src++; - if (!isascii(ch) || !isdigit(ch)) + if (!isascii((u_char)ch) || !isdigit((u_char)ch)) goto enoent; } } else goto enoent; bits = -1; - if (ch == '/' && isascii((unsigned char)(src[0])) && - isdigit((unsigned char)(src[0])) && dst > odst) { + if (ch == '/' && isascii((u_char)(src[0])) && + isdigit((u_char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /*%< Skip over the /. */ + ch = *src++; /* Skip over the /. */ bits = 0; do { n = strchr(digits, ch) - digits; INSIST(n >= 0 && n <= 9); bits *= 10; - bits += n; + bits += (int)n; if (bits > 32) - goto enoent; - } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); + goto emsgsize; + } while ((ch = *src++) != '\0' && isascii((u_char)ch) + && isdigit((u_char)ch)); if (ch != '\0') goto enoent; } @@ -149,29 +166,23 @@ inet_net_pton_ipv4(const char *src, u_ch goto enoent; /* If no CIDR spec was given, infer width from net class. */ if (bits == -1) { - if (*odst >= 240) /*%< Class E */ + if (*odst >= 240) /* Class E */ bits = 32; - else if (*odst >= 224) /*%< Class D */ - bits = 8; - else if (*odst >= 192) /*%< Class C */ + else if (*odst >= 224) /* Class D */ + bits = 4; + else if (*odst >= 192) /* Class C */ bits = 24; - else if (*odst >= 128) /*%< Class B */ + else if (*odst >= 128) /* Class B */ bits = 16; - else /*%< Class A */ + else /* Class A */ bits = 8; /* If imputed mask is narrower than specified octets, widen. */ - if (bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; - /* - * If there are no additional bits specified for a class D - * address adjust bits to 4. - */ - if (bits == 8 && *odst == 224) - bits = 4; + if (bits >= 8 && bits < ((dst - odst) * 8)) + bits = (int)(dst - odst) * 8; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { - if (size-- <= 0U) + if (size-- == 0) goto emsgsize; *dst++ = '\0'; } @@ -187,7 +198,8 @@ inet_net_pton_ipv4(const char *src, u_ch } static int -getbits(const char *src, int *bitsp) { +getbits(const char *src, int *bitsp) +{ static const char digits[] = "0123456789"; int n; int val; @@ -200,11 +212,11 @@ getbits(const char *src, int *bitsp) { pch = strchr(digits, ch); if (pch != NULL) { - if (n++ != 0 && val == 0) /*%< no leading zeros */ + if (n++ != 0 && val == 0) /* no leading zeros */ return (0); val *= 10; - val += (pch - digits); - if (val > 128) /*%< range */ + val += (int)(pch - digits); + if (val > 128) /* range */ return (0); continue; } @@ -217,7 +229,8 @@ getbits(const char *src, int *bitsp) { } static int -getv4(const char *src, u_char *dst, int *bitsp) { +getv4(const char *src, u_char *dst, int *bitsp) +{ static const char digits[] = "0123456789"; u_char *odst = dst; int n; @@ -231,16 +244,16 @@ getv4(const char *src, u_char *dst, int pch = strchr(digits, ch); if (pch != NULL) { - if (n++ != 0 && val == 0) /*%< no leading zeros */ + if (n++ != 0 && val == 0) /* no leading zeros */ return (0); val *= 10; - val += (pch - digits); - if (val > 255) /*%< range */ + val += (int)(pch - digits); + if (val > 255) /* range */ return (0); continue; } if (ch == '.' || ch == '/') { - if (dst - odst > 3) /*%< too many octets? */ + if (dst - odst > 3) /* too many octets? */ return (0); *dst++ = val; if (ch == '/') @@ -253,14 +266,15 @@ getv4(const char *src, u_char *dst, int } if (n == 0) return (0); - if (dst - odst > 3) /*%< too many octets? */ + if (dst - odst > 3) /* too many octets? */ return (0); *dst++ = val; return (1); } static int -inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { +inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) +{ static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; @@ -293,7 +307,7 @@ inet_net_pton_ipv6(const char *src, u_ch pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (++digits > 4) goto enoent; saw_xdigit = 1; @@ -322,7 +336,7 @@ inet_net_pton_ipv6(const char *src, u_ch tp += NS_INADDRSZ; saw_xdigit = 0; ipv4 = 1; - break; /*%< '\\0' was seen by inet_pton4(). */ + break; /* '\0' was seen by inet_pton4(). */ } if (ch == '/' && getbits(src, &bits) > 0) break; @@ -349,7 +363,7 @@ inet_net_pton_ipv6(const char *src, u_ch * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) @@ -378,7 +392,7 @@ inet_net_pton_ipv6(const char *src, u_ch return (-1); } -/*% +/* * int * inet_net_pton(af, src, dst, size) * convert network number from presentation to network format. @@ -392,7 +406,8 @@ inet_net_pton_ipv6(const char *src, u_ch * Paul Vixie (ISC), June 1996 */ int -inet_net_pton(int af, const char *src, void *dst, size_t size) { +inet_net_pton(int af, const char *src, void *dst, size_t size) +{ switch (af) { case AF_INET: return (inet_net_pton_ipv4(src, dst, size)); @@ -403,5 +418,3 @@ inet_net_pton(int af, const char *src, v return (-1); } } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_neta.c /usr/src/lib/libc/inet/inet_neta.c --- /home/reed/src/isc/libbind/libbind/inet/inet_neta.c 2005-04-26 23:56:20.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_neta.c 2013-06-05 09:26:11.000000000 -0500 @@ -1,44 +1,47 @@ +/* $NetBSD: inet_neta.c,v 1.3 2012/06/25 22:32:44 abs Exp $ */ + /* - * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_neta.c,v 1.3 2005/04/27 04:56:20 sra Exp $"; +#if 0 +static const char rcsid[] = "Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp "; +#else +__RCSID("$NetBSD: inet_neta.c,v 1.3 2012/06/25 22:32:44 abs Exp $"); +#endif #endif -#include "port_before.h" - +#include "namespace.h" #include #include #include #include +#include #include #include #include -#include "port_after.h" - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) +#ifdef __weak_alias +__weak_alias(inet_neta,_inet_neta) #endif -/*% +/* * char * * inet_neta(src, dst, size) * format a u_long network number into presentation format. @@ -50,40 +53,43 @@ static const char rcsid[] = "$Id: inet_n * Paul Vixie (ISC), July 1996 */ char * -inet_neta(src, dst, size) - u_long src; - char *dst; - size_t size; +inet_neta(u_long src, char *dst, size_t size) { char *odst = dst; - char *tp; + char *ep; + int advance; - while (src & 0xffffffff) { - u_char b = (src & 0xff000000) >> 24; + _DIAGASSERT(dst != NULL); + + if (src == 0x00000000) { + if (size < sizeof "0.0.0.0") + goto emsgsize; + strlcpy(dst, "0.0.0.0", size); + return dst; + } + ep = dst + size; + if (ep <= dst) + goto emsgsize; + while (src & 0xffffffffUL) { + u_char b = (u_char)((src & 0xff000000UL) >> 24); src <<= 8; - if (b) { - if (size < sizeof "255.") + if (b || src) { + advance = snprintf(dst, (size_t)(ep - dst), "%u", b); + if (advance <= 0 || advance >= ep - dst) goto emsgsize; - tp = dst; - dst += SPRINTF((dst, "%u", b)); + dst += advance; if (src != 0L) { + if (dst + 1 >= ep) + goto emsgsize; *dst++ = '.'; *dst = '\0'; } - size -= (size_t)(dst - tp); } } - if (dst == odst) { - if (size < sizeof "0.0.0.0") - goto emsgsize; - strcpy(dst, "0.0.0.0"); - } return (odst); emsgsize: errno = EMSGSIZE; return (NULL); } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_netof.c /usr/src/lib/libc/inet/inet_netof.c --- /home/reed/src/isc/libbind/libbind/inet/inet_netof.c 2013-04-04 17:43:29.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_netof.c 2004-05-20 18:13:02.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_netof.c,v 1.1 2004/05/20 23:13:02 christos Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -27,27 +29,32 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; +#if 0 +static char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: inet_netof.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ -#include "port_before.h" - +#include "namespace.h" #include #include #include -#include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_netof,_inet_netof) +#endif -/*% +/* * Return the network number from an internet * address; handles class a/b/c network #'s. */ -u_long -inet_netof(in) - struct in_addr in; +in_addr_t +inet_netof(struct in_addr in) { - register u_long i = ntohl(in.s_addr); + in_addr_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); @@ -56,5 +63,3 @@ inet_netof(in) else return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_network.c /usr/src/lib/libc/inet/inet_network.c --- /home/reed/src/isc/libbind/libbind/inet/inet_network.c 2013-04-04 17:43:29.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_network.c 2012-10-24 08:34:35.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_network.c,v 1.4 2008/01/20 04:56:08 christos Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -27,51 +29,63 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; +#if 0 +static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: inet_network.c,v 1.4 2008/01/20 04:56:08 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ -#include "port_before.h" - +#include "namespace.h" #include #include #include -#include -#include "port_after.h" +#include +#include +#ifdef _DIAGNOSTIC +#include /* for NULL */ +#endif + +#ifdef __weak_alias +__weak_alias(inet_network,_inet_network) +#endif -/*% +/* * Internet network address interpretation routine. * The library routines call this routine to interpret * network numbers. */ -u_long -inet_network(cp) - register const char *cp; +in_addr_t +inet_network(const char *cp) { - register u_long val, base, n, i; - register char c; - u_long parts[4], *pp = parts; - int digit; + in_addr_t val; + size_t i, n; + u_char c; + in_addr_t parts[4], *pp = parts; + int digit, base; + + _DIAGASSERT(cp != NULL); again: val = 0; base = 10; digit = 0; if (*cp == '0') digit = 1, base = 8, cp++; if (*cp == 'x' || *cp == 'X') - base = 16, cp++; + digit = 0, base = 16, cp++; while ((c = *cp) != 0) { - if (isdigit((unsigned char)c)) { - if (base == 8U && (c == '8' || c == '9')) + if (isdigit(c)) { + if (base == 8 && (c == '8' || c == '9')) return (INADDR_NONE); val = (val * base) + (c - '0'); cp++; digit = 1; continue; } - if (base == 16U && isxdigit((unsigned char)c)) { - val = (val << 4) + - (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); + if (base == 16 && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); cp++; digit = 1; continue; @@ -80,17 +94,17 @@ again: } if (!digit) return (INADDR_NONE); - if (pp >= parts + 4 || val > 0xffU) + if (pp >= parts + 4 || val > 0xff) return (INADDR_NONE); if (*cp == '.') { *pp++ = val, cp++; goto again; } - if (*cp && !isspace(*cp&0xff)) + if (*cp && !isspace((u_char) *cp)) return (INADDR_NONE); *pp++ = val; n = pp - parts; - if (n > 4U) + if (n > 4) return (INADDR_NONE); for (val = 0, i = 0; i < n; i++) { val <<= 8; @@ -98,5 +112,3 @@ again: } return (val); } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_ntoa.c /usr/src/lib/libc/inet/inet_ntoa.c --- /home/reed/src/isc/libbind/libbind/inet/inet_ntoa.c 2013-06-05 09:33:54.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_ntoa.c 2013-06-05 09:26:11.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -27,24 +29,28 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: inet_ntoa.c,v 1.3 2013-01-06 23:14:51 marka Exp $"; +#if 0 +static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ -#include "port_before.h" - +#include "namespace.h" #include #include #include #include - #include #include -#include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_ntoa,_inet_ntoa) +#endif -/*% +/* * Convert network-format internet address * to base 256 d.d.d.d representation. */ @@ -52,9 +58,7 @@ static const char rcsid[] = "$Id: inet_n inet_ntoa(struct in_addr in) { static char ret[18]; - strcpy(ret, "[inet_ntoa error]"); - (void) inet_ntop(AF_INET, &in, ret, sizeof ret); - return (ret); + strlcpy(ret, "[inet_ntoa error]", sizeof(ret)); + (void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret); + return ret; } - -/*! \file */ diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_ntop.c /usr/src/lib/libc/inet/inet_ntop.c --- /home/reed/src/isc/libbind/libbind/inet/inet_ntop.c 2005-11-03 16:59:52.000000000 -0600 +++ /usr/src/lib/libc/inet/inet_ntop.c 2013-06-05 09:26:11.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. @@ -15,12 +17,18 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp $"; +#if 0 +static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp"; +#else +__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ #include "port_before.h" +#include "namespace.h" #include #include #include @@ -29,16 +37,16 @@ static const char rcsid[] = "$Id: inet_n #include #include +#include #include #include +#include #include #include "port_after.h" -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) +#ifdef __weak_alias +__weak_alias(inet_ntop,_inet_ntop) #endif /*% @@ -46,8 +54,8 @@ static const char rcsid[] = "$Id: inet_n * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); -static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); +static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size); +static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); /* char * * inet_ntop(af, src, dst, size) @@ -58,12 +66,12 @@ static const char *inet_ntop6 __P((const * Paul Vixie, 1996. */ const char * -inet_ntop(af, src, dst, size) - int af; - const void *src; - char *dst; - size_t size; +inet_ntop(int af, const void *src, char *dst, socklen_t size) { + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + switch (af) { case AF_INET: return (inet_ntop4(src, dst, size)); @@ -78,7 +86,7 @@ inet_ntop(af, src, dst, size) /* const char * * inet_ntop4(src, dst, size) - * format an IPv4 address + * format an IPv4 address, more or less like inet_ntoa() * return: * `dst' (as a const) * notes: @@ -88,19 +96,21 @@ inet_ntop(af, src, dst, size) * Paul Vixie, 1996. */ static const char * -inet_ntop4(src, dst, size) - const u_char *src; - char *dst; - size_t size; +inet_ntop4(const u_char *src, char *dst, socklen_t size) { - static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; + int l; - if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) >= size) { + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + + l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", + src[0], src[1], src[2], src[3]); + if (l <= 0 || (socklen_t) l >= size) { errno = ENOSPC; return (NULL); } - strcpy(dst, tmp); + strlcpy(dst, tmp, size); return (dst); } @@ -111,10 +121,7 @@ inet_ntop4(src, dst, size) * Paul Vixie, 1996. */ static const char * -inet_ntop6(src, dst, size) - const u_char *src; - char *dst; - size_t size; +inet_ntop6(const u_char *src, char *dst, socklen_t size) { /* * Note that int32_t and int16_t need only be "at least" large enough @@ -123,10 +130,15 @@ inet_ntop6(src, dst, size) * Keep this in mind if you think this function should have been coded * to use pointer overlays. All the world's not a VAX. */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; + char *tp, *ep; struct { int base, len; } best, cur; u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; int i; + int advance; + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); /* * Preprocess: @@ -165,6 +177,7 @@ inet_ntop6(src, dst, size) * Format the result. */ tp = tmp; + ep = tmp + sizeof(tmp); for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && @@ -174,23 +187,35 @@ inet_ntop6(src, dst, size) continue; } /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) + if (i != 0) { + if (tp + 1 >= ep) + return (NULL); *tp++ = ':'; + } /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && (best.len == 6 || + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) + if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp))) return (NULL); tp += strlen(tp); break; } - tp += SPRINTF((tp, "%x", words[i])); + advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]); + if (advance <= 0 || advance >= ep - tp) + return (NULL); + tp += advance; } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) + (NS_IN6ADDRSZ / NS_INT16SZ)) { + if (tp + 1 >= ep) + return (NULL); *tp++ = ':'; + } + if (tp + 1 >= ep) + return (NULL); *tp++ = '\0'; /* @@ -200,7 +225,7 @@ inet_ntop6(src, dst, size) errno = ENOSPC; return (NULL); } - strcpy(dst, tmp); + strlcpy(dst, tmp, size); return (dst); } diff -pruN /home/reed/src/isc/libbind/libbind/inet/inet_pton.c /usr/src/lib/libc/inet/inet_pton.c --- /home/reed/src/isc/libbind/libbind/inet/inet_pton.c 2005-07-28 01:51:47.000000000 -0500 +++ /usr/src/lib/libc/inet/inet_pton.c 2013-06-05 09:26:11.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. @@ -15,28 +17,43 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp $"; +#if 0 +static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp"; +#else +__RCSID("$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ #include "port_before.h" + +#include "namespace.h" #include #include #include #include #include #include +#include #include +#include +#include #include + #include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_pton,_inet_pton) +#endif + /*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static int inet_pton4 __P((const char *src, u_char *dst)); -static int inet_pton6 __P((const char *src, u_char *dst)); +static int inet_pton4(const char *src, u_char *dst, int pton); +static int inet_pton6(const char *src, u_char *dst); /* int * inet_pton(af, src, dst) @@ -50,14 +67,15 @@ static int inet_pton6 __P((const char *s * Paul Vixie, 1996. */ int -inet_pton(af, src, dst) - int af; - const char *src; - void *dst; +inet_pton(int af, const char *src, void *dst) { + + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + switch (af) { case AF_INET: - return (inet_pton4(src, dst)); + return (inet_pton4(src, dst, 1)); case AF_INET6: return (inet_pton6(src, dst)); default: @@ -68,54 +86,123 @@ inet_pton(af, src, dst) } /* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. + * inet_pton4(src, dst, pton) + * when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand. + * when last arg is 1: inet_pton(). decimal dotted-quad only. * return: - * 1 if `src' is a valid dotted quad, else 0. + * 1 if `src' is a valid input, else 0. * notice: * does not touch `dst' unless it's returning 1. * author: * Paul Vixie, 1996. */ static int -inet_pton4(src, dst) - const char *src; - u_char *dst; +inet_pton4(const char *src, u_char *dst, int pton) { - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - u_char tmp[NS_INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; + u_int32_t val; + u_int digit, base; + ptrdiff_t n; + unsigned char c; + u_int parts[4]; + u_int *pp = parts; - if ((pch = strchr(digits, ch)) != NULL) { - u_int new = *tp * 10 + (pch - digits); + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); - if (saw_digit && *tp == 0) - return (0); - if (new > 255) - return (0); - *tp = new; - if (!saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) + c = *src; + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, isdigit=decimal. + */ + if (!isdigit(c)) + return (0); + val = 0; base = 10; + if (c == '0') { + c = *++src; + if (c == 'x' || c == 'X') + base = 16, c = *++src; + else if (isdigit(c) && c != '9') + base = 8; + } + /* inet_pton() takes decimal only */ + if (pton && base != 10) + return (0); + for (;;) { + if (isdigit(c)) { + digit = c - '0'; + if (digit >= base) + break; + val = (val * base) + digit; + c = *++src; + } else if (base == 16 && isxdigit(c)) { + digit = c + 10 - (islower(c) ? 'a' : 'A'); + if (digit >= 16) + break; + val = (val << 4) | digit; + c = *++src; + } else + break; + } + if (c == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16 bits) + * a.b (with b treated as 24 bits) + * a (with a treated as 32 bits) + */ + if (pp >= parts + 3) return (0); - *++tp = 0; - saw_digit = 0; + *pp++ = val; + c = *++src; } else - return (0); + break; } - if (octets < 4) + /* + * Check for trailing characters. + */ + if (c != '\0' && !isspace(c)) + return (0); + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + /* inet_pton() takes dotted-quad only. it does not take shorthand. */ + if (pton && n != 4) return (0); - memcpy(dst, tmp, NS_INADDRSZ); + switch (n) { + + case 0: + return (0); /* initial nondigit */ + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if (parts[0] > 0xff || val > 0xffffff) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if ((parts[0] | parts[1]) > 0xff || val > 0xffff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if ((parts[0] | parts[1] | parts[2] | val) > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + if (dst) { + val = htonl(val); + memcpy(dst, &val, NS_INADDRSZ); + } return (1); } @@ -133,9 +220,7 @@ inet_pton4(src, dst) * Paul Vixie, 1996. */ static int -inet_pton6(src, dst) - const char *src; - u_char *dst; +inet_pton6(const char *src, u_char *dst) { static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; @@ -144,6 +229,9 @@ inet_pton6(src, dst) int ch, seen_xdigits; u_int val; + _DIAGASSERT(src != NULL); + _DIAGASSERT(dst != NULL); + memset((tp = tmp), '\0', NS_IN6ADDRSZ); endp = tp + NS_IN6ADDRSZ; colonp = NULL; @@ -161,7 +249,7 @@ inet_pton6(src, dst) pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (++seen_xdigits > 4) return (0); continue; @@ -173,9 +261,8 @@ inet_pton6(src, dst) return (0); colonp = tp; continue; - } else if (*src == '\0') { + } else if (*src == '\0') return (0); - } if (tp + NS_INT16SZ > endp) return (0); *tp++ = (u_char) (val >> 8) & 0xff; @@ -185,7 +272,7 @@ inet_pton6(src, dst) continue; } if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { + inet_pton4(curtok, tp, 1) > 0) { tp += NS_INADDRSZ; seen_xdigits = 0; break; /*%< '\\0' was seen by inet_pton4(). */ @@ -203,7 +290,7 @@ inet_pton6(src, dst) * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) diff -pruN /home/reed/src/isc/libbind/libbind/inet/nsap_addr.c /usr/src/lib/libc/inet/nsap_addr.c --- /home/reed/src/isc/libbind/libbind/inet/nsap_addr.c 2005-07-28 01:51:48.000000000 -0500 +++ /usr/src/lib/libc/inet/nsap_addr.c 2012-10-24 08:34:35.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: nsap_addr.c,v 1.6 2009/04/12 17:07:17 christos Exp $ */ + /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. @@ -15,12 +17,18 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nsap_addr.c,v 1.5 2005/07/28 06:51:48 marka Exp $"; +#if 0 +static const char rcsid[] = "Id: nsap_addr.c,v 1.5 2005/07/28 06:51:48 marka Exp"; +#else +__RCSID("$NetBSD: nsap_addr.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ #include "port_before.h" +#include "namespace.h" #include #include #include @@ -29,12 +37,18 @@ static const char rcsid[] = "$Id: nsap_a #include #include +#include #include #include #include #include "port_after.h" +#ifdef __weak_alias +__weak_alias(inet_nsap_addr,_inet_nsap_addr) +__weak_alias(inet_nsap_ntoa,_inet_nsap_ntoa) +#endif + static char xtob(int c) { return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); @@ -45,6 +59,9 @@ inet_nsap_addr(const char *ascii, u_char u_char c, nib; u_int len = 0; + _DIAGASSERT(ascii != NULL); + _DIAGASSERT(binary != NULL); + if (ascii[0] != '0' || (ascii[1] != 'x' && ascii[1] != 'X')) return (0); ascii += 2; @@ -83,6 +100,8 @@ inet_nsap_ntoa(int binlen, const u_char char *tmpbuf = inet_nsap_ntoa_tmpbuf; char *start; + _DIAGASSERT(binary != NULL); + if (ascii) start = ascii; else { @@ -97,7 +116,7 @@ inet_nsap_ntoa(int binlen, const u_char binlen = 255; for (i = 0; i < binlen; i++) { - nib = *binary >> 4; + nib = (u_int32_t)*binary >> 4; *ascii++ = nib + (nib < 10 ? '0' : '7'); nib = *binary++ & 0x0f; *ascii++ = nib + (nib < 10 ? '0' : '7'); --- /home/reed/src/isc/libbind/libbind/inet/inet_addr.c 2013-06-05 09:33:54.000000000 -0500 +++ /usr/src/common/lib/libc/inet/inet_addr.c 2012-10-24 08:07:13.000000000 -0500 @@ -1,3 +1,5 @@ +/* $NetBSD: inet_addr.c,v 1.2 2008/02/16 17:37:13 apb Exp $ */ + /* * Copyright (c) 1983, 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -10,7 +12,11 @@ * 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 University nor the names of its contributors + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -64,13 +70,20 @@ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; -static const char rcsid[] = "$Id: inet_addr.c,v 1.6 2013-01-06 23:14:51 marka Exp $"; +static const char rcsid[] = "Id: inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp"; +#else +__RCSID("$NetBSD: inet_addr.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ #include "port_before.h" +#include "namespace.h" #include #include @@ -81,11 +94,19 @@ static const char rcsid[] = "$Id: inet_a #include "port_after.h" -/*% +#ifdef __weak_alias +__weak_alias(inet_aton,_inet_aton) +#endif +#else +#include +#include +#endif + +/* * Ascii internet address interpretation routine. * The value returned is in network order. */ -u_long +uint32_t inet_addr(const char *cp) { struct in_addr val; @@ -94,7 +115,7 @@ inet_addr(const char *cp) { return (INADDR_NONE); } -/*% +/* * Check whether "cp" is a valid ascii representation * of an Internet address and convert to a binary address. * Returns 1 if the address is valid, 0 if not. @@ -103,11 +124,11 @@ inet_addr(const char *cp) { */ int inet_aton(const char *cp, struct in_addr *addr) { - u_long val; + uint32_t val; int base, n; char c; - u_int8_t parts[4]; - u_int8_t *pp = parts; + uint8_t parts[4]; + uint8_t *pp = parts; int digit; c = *cp; @@ -175,22 +196,22 @@ inet_aton(const char *cp, struct in_addr */ n = pp - parts + 1; switch (n) { - case 1: /*%< a -- 32 bits */ + case 1: /* a -- 32 bits */ break; - case 2: /*%< a.b -- 8.24 bits */ + case 2: /* a.b -- 8.24 bits */ if (val > 0xffffffU) return (0); val |= parts[0] << 24; break; - case 3: /*%< a.b.c -- 8.8.16 bits */ + case 3: /* a.b.c -- 8.8.16 bits */ if (val > 0xffffU) return (0); val |= (parts[0] << 24) | (parts[1] << 16); break; - case 4: /*%< a.b.c.d -- 8.8.8.8 bits */ + case 4: /* a.b.c.d -- 8.8.8.8 bits */ if (val > 0xffU) return (0); val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); @@ -200,5 +221,3 @@ inet_aton(const char *cp, struct in_addr addr->s_addr = htonl(val); return (1); } - -/*! \file */