Index: cpukit/libnetworking/include/arpa/inet.h
===================================================================
--- cpukit/libnetworking/include/arpa/inet.h	(revision 3bc19384a7be162b5c925add66dd879041db67a0)
+++ cpukit/libnetworking/include/arpa/inet.h	(revision 9b035a0a4a927007e88b7347782668557903bb31)
@@ -113,4 +113,25 @@
 #endif
 
+/* XXX all new diversions!! argh!! */
+#if __BSD_VISIBLE
+#define	inet_addr		__inet_addr
+#define	inet_aton		__inet_aton
+#define	inet_lnaof		__inet_lnaof
+#define	inet_makeaddr		__inet_makeaddr
+#define	inet_neta		__inet_neta
+#define	inet_netof		__inet_netof
+#define	inet_network		__inet_network
+#define	inet_net_ntop		__inet_net_ntop
+#define	inet_net_pton		__inet_net_pton
+#define	inet_cidr_ntop		__inet_cidr_ntop
+#define	inet_cidr_pton		__inet_cidr_pton
+#define	inet_ntoa		__inet_ntoa
+#define	inet_ntoa_r		__inet_ntoa_r
+#define	inet_pton		__inet_pton
+#define	inet_ntop		__inet_ntop
+#define	inet_nsap_addr		__inet_nsap_addr
+#define	inet_nsap_ntoa		__inet_nsap_ntoa
+#endif /* __BSD_VISIBLE */
+
 __BEGIN_DECLS
 #ifndef _BYTEORDER_PROTOTYPED
Index: cpukit/libnetworking/libc/inet_addr.c
===================================================================
--- cpukit/libnetworking/libc/inet_addr.c	(revision 3bc19384a7be162b5c925add66dd879041db67a0)
+++ cpukit/libnetworking/libc/inet_addr.c	(revision 9b035a0a4a927007e88b7347782668557903bb31)
@@ -1,5 +1,3 @@
 /*
- * ++Copyright++ 1983, 1990, 1993
- * -
  * Copyright (c) 1983, 1990, 1993
  *    The Regents of the University of California.  All rights reserved.
@@ -13,9 +11,5 @@
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 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
+ * 3. 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.
@@ -32,5 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- * -
+ */
+
+/*
  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  * 
@@ -50,25 +46,47 @@
  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  * SOFTWARE.
- * -
- * --Copyright--
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
+ */
+
+/*
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
+ * Portions 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char sccsid[] = "@(#)inet_addr.c	8.1 (Berkeley) 6/17/93";
+static const char rcsid[] = "$Id: inet_addr.c,v 1.5 2005/04/27 04:56:19 sra Exp $";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/inet/inet_addr.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include "port_before.h"
 
 #include <sys/param.h>
+
 #include <netinet/in.h>
 #include <arpa/inet.h>
+
 #include <ctype.h>
 
-/*
- * ASCII internet address interpretation routine.
+#include "port_after.h"
+
+/*%
+ * Ascii internet address interpretation routine.
  * The value returned is in network order.
  */
-in_addr_t
-inet_addr(
-	const char *cp)
-{
+in_addr_t		/* XXX should be struct in_addr :( */
+inet_addr(const char *cp) {
 	struct in_addr val;
 
@@ -78,6 +96,6 @@
 }
 
-/* 
- * Check whether "cp" is a valid ASCII representation
+/*%
+ * 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.
@@ -86,13 +104,11 @@
  */
 int
-inet_aton(
-	const char *cp,
-	struct in_addr *addr)
-{
-	in_addr_t val;
-	register int base, n;
-	register char c;
-	uint32_t parts[4];
-	register uint32_t *pp = parts;
+inet_aton(const char *cp, struct in_addr *addr) {
+	u_long val;
+	int base, n;
+	char c;
+	u_int8_t parts[4];
+	u_int8_t *pp = parts;
+	int digit;
 
 	c = *cp;
@@ -105,20 +121,27 @@
 		if (!isdigit((unsigned char)c))
 			return (0);
-		val = 0; base = 10;
+		val = 0; base = 10; digit = 0;
 		if (c == '0') {
 			c = *++cp;
 			if (c == 'x' || c == 'X')
 				base = 16, c = *++cp;
-			else
+			else {
 				base = 8;
+				digit = 1 ;
+			}
 		}
 		for (;;) {
-			if (isascii((unsigned char)c) && isdigit((unsigned char)c)) {
+			if (isascii(c) && isdigit((unsigned char)c)) {
+				if (base == 8 && (c == '8' || c == '9'))
+					return (0);
 				val = (val * base) + (c - '0');
 				c = *++cp;
-			} else if (base == 16 && isascii((unsigned char)c) && isxdigit((unsigned char)c)) {
+				digit = 1;
+			} else if (base == 16 && isascii(c) && 
+				   isxdigit((unsigned char)c)) {
 				val = (val << 4) |
 					(c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
 				c = *++cp;
+				digit = 1;
 			} else
 				break;
@@ -131,5 +154,5 @@
 			 *	a.b	(with b treated as 24 bits)
 			 */
-			if (pp >= parts + 3)
+			if (pp >= parts + 3 || val > 0xffU)
 				return (0);
 			*pp++ = val;
@@ -141,5 +164,10 @@
 	 * Check for trailing characters.
 	 */
-	if (c != '\0' && (!isascii((unsigned char)c) || !isspace((unsigned char)c)))
+	if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c)))
+		return (0);
+	/*
+	 * Did we get a valid digit?
+	 */
+	if (!digit)
 		return (0);
 	/*
@@ -149,25 +177,21 @@
 	n = pp - parts + 1;
 	switch (n) {
-
-	case 0:
-		return (0);		/* initial nondigit */
-
-	case 1:				/* a -- 32 bits */
-		break;
-
-	case 2:				/* a.b -- 8.24 bits */
-		if (val > 0xffffff)
+	case 1:				/*%< a -- 32 bits */
+		break;
+
+	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 */
-		if (val > 0xffff)
+	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 */
-		if (val > 0xff)
+	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);
@@ -178,2 +202,13 @@
 	return (1);
 }
+
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_addr
+__weak_reference(__inet_addr, inet_addr);
+#undef inet_aton
+__weak_reference(__inet_aton, inet_aton);
+
+/*! \file */
Index: cpukit/libnetworking/libc/inet_ntoa.c
===================================================================
--- cpukit/libnetworking/libc/inet_ntoa.c	(revision 3bc19384a7be162b5c925add66dd879041db67a0)
+++ cpukit/libnetworking/libc/inet_ntoa.c	(revision 9b035a0a4a927007e88b7347782668557903bb31)
@@ -1,3 +1,3 @@
-/*
+/*-
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -11,9 +11,5 @@
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 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
+ * 3. 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.
@@ -32,7 +28,12 @@
  */
 
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
+#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.2 2005/04/27 04:56:21 sra Exp $";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/inet/inet_ntoa.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include "port_before.h"
 
 #include <sys/types.h>
@@ -40,15 +41,16 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
+
 #include <stdio.h>
-#include <sys/libkern.h> /* for strcpy */
+#include <string.h>
 
-/*
+#include "port_after.h"
+
+/*%
  * Convert network-format internet address
  * to base 256 d.d.d.d representation.
  */
-char *
-inet_ntoa(
-	struct in_addr in)
-{
+/*const*/ char *
+inet_ntoa(struct in_addr in) {
 	static char ret[18];
 
@@ -57,2 +59,20 @@
 	return (ret);
 }
+
+char *
+inet_ntoa_r(struct in_addr in, char *buf, socklen_t size)
+{
+
+	(void) inet_ntop(AF_INET, &in, buf, size);
+	return (buf);
+}
+
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_ntoa
+__weak_reference(__inet_ntoa, inet_ntoa);
+__weak_reference(__inet_ntoa_r, inet_ntoa_r);
+
+/*! \file */
Index: cpukit/libnetworking/libc/inet_ntop.c
===================================================================
--- cpukit/libnetworking/libc/inet_ntop.c	(revision 3bc19384a7be162b5c925add66dd879041db67a0)
+++ cpukit/libnetworking/libc/inet_ntop.c	(revision 9b035a0a4a927007e88b7347782668557903bb31)
@@ -1,3 +1,5 @@
-/* Copyright (c) 1996 by Internet Software Consortium.
+/*
+ * 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
@@ -5,31 +7,35 @@
  * copyright notice and this permission notice appear in all copies.
  *
- * 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.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
+ * 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 const char rcsid[] = "$Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp $";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/inet/inet_ntop.c 298226 2016-04-18 21:05:15Z avos $");
+
+#include "port_before.h"
 
 #include <sys/param.h>
-#include <sys/types.h>
 #include <sys/socket.h>
+
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
+
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
-#define SPRINTF(x) ((size_t)sprintf x)
-
-/*
+#include "port_after.h"
+
+/*%
  * 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.
@@ -39,5 +45,5 @@
 static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
 
-/* char *
+/* const char *
  * inet_ntop(af, src, dst, size)
  *	convert a network format address to presentation format.
@@ -48,9 +54,6 @@
  */
 const char *
-inet_ntop(
-	int af,
-	const void *src,
-	char *dst,
-	socklen_t size)
+inet_ntop(int af, const void * __restrict src, char * __restrict dst,
+    socklen_t size)
 {
 	switch (af) {
@@ -68,5 +71,5 @@
 /* const char *
  * inet_ntop4(src, dst, size)
- *	format an IPv4 address, more or less like inet_ntoa()
+ *	format an IPv4 address
  * return:
  *	`dst' (as a const)
@@ -78,17 +81,16 @@
  */
 static const char *
-inet_ntop4(
-	const u_char *src,
-	char *dst,
-	socklen_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"];
-
-	if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
+	int l;
+
+	l = snprintf(tmp, sizeof(tmp), fmt, 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);
 }
@@ -101,8 +103,5 @@
  */
 static const char *
-inet_ntop6(
-	const u_char *src,
-	char *dst,
-	socklen_t size)
+inet_ntop6(const u_char *src, char *dst, socklen_t size)
 {
 	/*
@@ -127,7 +126,7 @@
 		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
 	best.base = -1;
-	best.len  = 0;
+	best.len = 0;
 	cur.base = -1;
-	cur.len  = 0;
+	cur.len = 0;
 	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
 		if (words[i] == 0) {
@@ -167,15 +166,18 @@
 			*tp++ = ':';
 		/* Is this address an encapsulated IPv4? */
-		if (i == 6 && best.base == 0 &&
-		    (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
-			if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
+		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))) {
+				errno = ENOSPC;
 				return (NULL);
+			}
 			tp += strlen(tp);
 			break;
 		}
-		tp += SPRINTF((tp, "%x", words[i]));
+		tp += sprintf(tp, "%x", words[i]);
 	}
 	/* Was it a trailing run of 0x00's? */
-	if (best.base != -1 && (best.base + best.len) ==
+	if (best.base != -1 && (best.base + best.len) == 
 	    (NS_IN6ADDRSZ / NS_INT16SZ))
 		*tp++ = ':';
@@ -185,5 +187,5 @@
 	 * Check for overflow, copy, and we're done.
 	 */
-	if ((size_t)(tp - tmp) > size) {
+	if ((socklen_t)(tp - tmp) > size) {
 		errno = ENOSPC;
 		return (NULL);
@@ -192,2 +194,11 @@
 	return (dst);
 }
+
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_ntop
+__weak_reference(__inet_ntop, inet_ntop);
+
+/*! \file */
