summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-06-07 07:11:23 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-06-07 13:02:21 +0200
commit9b035a0a4a927007e88b7347782668557903bb31 (patch)
tree40eed578f86fbd6537fb645801cd6e2de66f3beb
parentnetwork: Move header files (diff)
downloadrtems-9b035a0a4a927007e88b7347782668557903bb31.tar.bz2
network: Update <arpa/inet.h>
Update #2833.
-rw-r--r--cpukit/libnetworking/include/arpa/inet.h21
-rw-r--r--cpukit/libnetworking/libc/inet_addr.c129
-rw-r--r--cpukit/libnetworking/libc/inet_ntoa.c50
-rw-r--r--cpukit/libnetworking/libc/inet_ntop.c91
-rw-r--r--cpukit/libnetworking/libc/port_after.h0
-rw-r--r--cpukit/libnetworking/libc/port_before.h0
6 files changed, 189 insertions, 102 deletions
diff --git a/cpukit/libnetworking/include/arpa/inet.h b/cpukit/libnetworking/include/arpa/inet.h
index 91e3a828ab..d71c92748e 100644
--- a/cpukit/libnetworking/include/arpa/inet.h
+++ b/cpukit/libnetworking/include/arpa/inet.h
@@ -112,6 +112,27 @@ struct in_addr {
#define _STRUCT_IN_ADDR_DECLARED
#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
#define _BYTEORDER_PROTOTYPED
diff --git a/cpukit/libnetworking/libc/inet_addr.c b/cpukit/libnetworking/libc/inet_addr.c
index 9820e25ce2..2e1dc35324 100644
--- a/cpukit/libnetworking/libc/inet_addr.c
+++ b/cpukit/libnetworking/libc/inet_addr.c
@@ -1,6 +1,4 @@
/*
- * ++Copyright++ 1983, 1990, 1993
- * -
* Copyright (c) 1983, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -12,11 +10,7 @@
* 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. 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.
*
@@ -31,7 +25,9 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- * -
+ */
+
+/*
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
@@ -49,27 +45,49 @@
* 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.
- * -
- * --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;
if (inet_aton(cp, &val))
@@ -77,23 +95,21 @@ inet_addr(
return (INADDR_NONE);
}
-/*
- * 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.
* This replaces inet_addr, the return value from which
* cannot distinguish between failure and a local broadcast address.
*/
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;
for (;;) {
@@ -104,22 +120,29 @@ inet_aton(
*/
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;
}
@@ -130,7 +153,7 @@ inet_aton(
* a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
- if (pp >= parts + 3)
+ if (pp >= parts + 3 || val > 0xffU)
return (0);
*pp++ = val;
c = *++cp;
@@ -140,7 +163,12 @@ inet_aton(
/*
* 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);
/*
* Concoct the address according to
@@ -148,27 +176,23 @@ inet_aton(
*/
n = pp - parts + 1;
switch (n) {
-
- case 0:
- return (0); /* initial nondigit */
-
- case 1: /* a -- 32 bits */
+ case 1: /*%< a -- 32 bits */
break;
- case 2: /* a.b -- 8.24 bits */
- if (val > 0xffffff)
+ 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);
break;
@@ -177,3 +201,14 @@ inet_aton(
addr->s_addr = htonl(val);
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 */
diff --git a/cpukit/libnetworking/libc/inet_ntoa.c b/cpukit/libnetworking/libc/inet_ntoa.c
index 8f14aa4f98..0fecfe36da 100644
--- a/cpukit/libnetworking/libc/inet_ntoa.c
+++ b/cpukit/libnetworking/libc/inet_ntoa.c
@@ -1,4 +1,4 @@
-/*
+/*-
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -10,11 +10,7 @@
* 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. 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.
*
@@ -31,28 +27,52 @@
* SUCH DAMAGE.
*/
-#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>
#include <sys/socket.h>
#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];
strcpy(ret, "[inet_ntoa error]");
(void) inet_ntop(AF_INET, &in, ret, sizeof ret);
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 */
diff --git a/cpukit/libnetworking/libc/inet_ntop.c b/cpukit/libnetworking/libc/inet_ntop.c
index 2e28dbbcd0..b54eec714e 100644
--- a/cpukit/libnetworking/libc/inet_ntop.c
+++ b/cpukit/libnetworking/libc/inet_ntop.c
@@ -1,36 +1,42 @@
-/* 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
* 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 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.
+ * 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 HAVE_CONFIG_H
-#include "config.h"
-#endif
+#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.
*/
@@ -38,7 +44,7 @@
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 *
+/* const char *
* inet_ntop(af, src, dst, size)
* convert a network format address to presentation format.
* return:
@@ -47,11 +53,8 @@ static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
* Paul Vixie, 1996.
*/
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) {
case AF_INET:
@@ -67,7 +70,7 @@ inet_ntop(
/* 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)
* notes:
@@ -77,19 +80,18 @@ inet_ntop(
* Paul Vixie, 1996.
*/
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"];
+ int l;
- if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
+ 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);
}
@@ -100,10 +102,7 @@ inet_ntop4(
* Paul Vixie, 1996.
*/
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)
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
@@ -126,9 +125,9 @@ inet_ntop6(
for (i = 0; i < NS_IN6ADDRSZ; i++)
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) {
if (cur.base == -1)
@@ -166,17 +165,20 @@ inet_ntop6(
if (i != 0)
*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++ = ':';
*tp++ = '\0';
@@ -184,10 +186,19 @@ inet_ntop6(
/*
* Check for overflow, copy, and we're done.
*/
- if ((size_t)(tp - tmp) > size) {
+ if ((socklen_t)(tp - tmp) > size) {
errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
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 */
diff --git a/cpukit/libnetworking/libc/port_after.h b/cpukit/libnetworking/libc/port_after.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cpukit/libnetworking/libc/port_after.h
diff --git a/cpukit/libnetworking/libc/port_before.h b/cpukit/libnetworking/libc/port_before.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cpukit/libnetworking/libc/port_before.h