[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/build/uClibc/test/inet/Makefile b/ap/build/uClibc/test/inet/Makefile
new file mode 100644
index 0000000..9605dca
--- /dev/null
+++ b/ap/build/uClibc/test/inet/Makefile
@@ -0,0 +1,7 @@
+# uClibc inet tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+include ../Rules.mak
+-include Makefile.in
+include ../Test.mak
diff --git a/ap/build/uClibc/test/inet/Makefile.in b/ap/build/uClibc/test/inet/Makefile.in
new file mode 100644
index 0000000..0710d3d
--- /dev/null
+++ b/ap/build/uClibc/test/inet/Makefile.in
@@ -0,0 +1,11 @@
+# uClibc inet tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+ifeq ($(UCLIBC_HAS_IPV4)$(UCLIBC_HAS_IPV6),)
+TESTS_DISABLED := bug-if1 gethost_r-align gethostid if_nameindex tst-aton \
+	tst-network tst-ntoa
+endif
+
+ifeq ($(UCLIBC_HAS_SOCKET)$(UCLIBC_HAS_IPV4)$(UCLIBC_HAS_IPV6),)
+TESTS_DISABLED := tst-ether_aton tst-ethers tst-ethers-line
+endif
diff --git a/ap/build/uClibc/test/inet/bug-if1.c b/ap/build/uClibc/test/inet/bug-if1.c
new file mode 100644
index 0000000..6bcd175
--- /dev/null
+++ b/ap/build/uClibc/test/inet/bug-if1.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <net/if.h>
+
+
+static int
+do_test (void)
+{
+  char buf[IF_NAMESIZE];
+  /* Index 0 is always invalid (see RFC 3493).  */
+  char *cp = if_indextoname (0, buf);
+  if (cp != NULL)
+    {
+      printf ("invalid index returned result \"%s\"\n", cp);
+      return 1;
+    }
+  else if (errno != ENXIO)
+    {
+      int err = errno;
+      char errbuf1[256];
+      char errbuf2[256];
+
+      printf ("errno = %d (%s), expected %d (%s)\n",
+	      err, strerror_r (err, errbuf1, sizeof (errbuf1)),
+	      ENXIO, strerror_r (ENXIO, errbuf2, sizeof (errbuf2)));
+      return 1;
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/ap/build/uClibc/test/inet/gethost_r-align.c b/ap/build/uClibc/test/inet/gethost_r-align.c
new file mode 100644
index 0000000..53ce93a
--- /dev/null
+++ b/ap/build/uClibc/test/inet/gethost_r-align.c
@@ -0,0 +1,50 @@
+/* Since the reentrant gethost functions take a char * buffer,
+ * we have to make sure they internally do not assume alignment.
+ * The actual return values are not relevant.  If the test fails,
+ * it'll be due to an alignment exception which means the test
+ * app is killed by the kernel.
+ */
+
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+int main(int argc, char *argv[])
+{
+	size_t i;
+	char buf[1024];
+	in_addr_t addr;
+
+	addr = inet_addr("127.0.0.1");
+
+	for (i = 0; i < sizeof(size_t) * 2; ++i) {
+		struct hostent hent, *hentres;
+		int ret, herr;
+
+		printf("Testing misalignment of %2zi bytes: ", i);
+
+		memset(&hent, 0x00, sizeof(hent));
+		ret = gethostent_r(&hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+		printf("%sgethostent_r() ", (ret ? "!!!" : ""));
+
+		memset(&hent, 0x00, sizeof(hent));
+		ret = gethostbyname_r("localhost", &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+		printf("%sgethostbyname_r() ", (ret ? "!!!" : ""));
+
+		memset(&hent, 0x00, sizeof(hent));
+		ret = gethostbyname2_r("localhost", AF_INET, &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+		printf("%sgethostbyname2_r() ", (ret ? "!!!" : ""));
+
+		memset(&hent, 0x00, sizeof(hent));
+		ret = gethostbyaddr_r(&addr, sizeof(addr), AF_INET, &hent, buf + i, sizeof(buf) - i, &hentres, &herr);
+		printf("%sgethostbyaddr_r() ", (ret ? "!!!" : ""));
+
+		puts("OK!");
+	}
+
+	return 0;
+}
diff --git a/ap/build/uClibc/test/inet/gethostid.c b/ap/build/uClibc/test/inet/gethostid.c
new file mode 100644
index 0000000..2951665
--- /dev/null
+++ b/ap/build/uClibc/test/inet/gethostid.c
@@ -0,0 +1,6 @@
+#include <unistd.h>
+#include <stdio.h>
+int main(void) {
+	printf("hostid=%d\n", gethostid());
+	return 0;
+}
diff --git a/ap/build/uClibc/test/inet/getnetent.c b/ap/build/uClibc/test/inet/getnetent.c
new file mode 100644
index 0000000..6607cea
--- /dev/null
+++ b/ap/build/uClibc/test/inet/getnetent.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <netdb.h>
+int main(void)
+{
+	struct netent *net;
+	setnetent(0);
+	while ((net = getnetent())) {
+		while (net->n_net && !((net->n_net >> 24) & 0xff)) {
+			net->n_net <<= 8;
+		}
+		printf("%lu.%lu.%lu.%lu\n",
+			   (net->n_net >> 24) & 0xff, (net->n_net >> 16) & 0xff,
+			   (net->n_net >> 8) & 0xff, net->n_net & 0xff);
+	}
+	endnetent();
+	return 0;
+}
diff --git a/ap/build/uClibc/test/inet/if_nameindex.c b/ap/build/uClibc/test/inet/if_nameindex.c
new file mode 100644
index 0000000..126c5ba
--- /dev/null
+++ b/ap/build/uClibc/test/inet/if_nameindex.c
@@ -0,0 +1,61 @@
+/* if_nameindex.c: test the if_nameindex() function
+ *
+ * Copyright (C) 2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <net/if.h>
+
+static char ifname[IF_NAMESIZE];
+
+static void test_if_nameindex(void)
+{
+	size_t i;
+	struct if_nameindex *ret;
+
+	ret = if_nameindex();
+
+	if (ret == NULL) {
+		perror("if_nameindex()");
+		exit(1);
+	}
+
+	printf("--- if_nameindex()\n");
+	for (i=0; ret[i].if_name; ++i)
+		printf("%i: %s\n", ret[i].if_index, ret[i].if_name);
+
+	if_freenameindex(ret);
+}
+
+static void test_if_indextoname(void)
+{
+	if (if_indextoname(1, ifname) == NULL) {
+		perror("if_nameindex()");
+		exit(1);
+	}
+
+	printf("if_indextoname(1) = %s\n", ifname);
+}
+
+static void test_if_nametoindex(void)
+{
+	int ifindex = if_nametoindex(ifname);
+
+	if (ifindex == 0) {
+		perror("if_nametoindex()");
+		exit(1);
+	}
+
+	printf("if_nametoindex(%s) = %i\n", ifname, ifindex);
+}
+
+int main(void)
+{
+	test_if_nameindex();
+	test_if_indextoname();
+	test_if_nametoindex();
+	return 0;
+}
diff --git a/ap/build/uClibc/test/inet/tst-aton.c b/ap/build/uClibc/test/inet/tst-aton.c
new file mode 100644
index 0000000..3e945f1
--- /dev/null
+++ b/ap/build/uClibc/test/inet/tst-aton.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+/* Note: uClibc only supports the standard notation 'a.b.c.d' */
+
+static struct tests
+{
+  const char *input;
+  int valid;
+  uint32_t result;
+} tests[] =
+{
+  { "", 0, 0 },
+  { "-1", 0, 0 },
+/*
+  { "256", 1, 0x00000100 },
+*/
+  { "256.", 0, 0 },
+  { "256a", 0, 0 },
+/*
+  { "0x100", 1, 0x00000100 },
+  { "0200.0x123456", 1, 0x80123456 },
+  { "0300.0x89123456.", 0 ,0 },
+  { "0100.-0xffff0000", 0, 0 },
+  { "0.0xffffff", 1, 0x00ffffff },
+  { "0.0x1000000", 0, 0 },
+  { "0377.16777215", 1, 0xffffffff },
+  { "0377.16777216", 0, 0 },
+  { "0x87.077777777", 1, 0x87ffffff },
+  { "0x87.0100000000", 0, 0 },
+  { "0.1.3", 1, 0x00010003 },
+*/
+  { "0.256.3", 0, 0 },
+  { "256.1.3", 0, 0 },
+/*
+  { "0.1.0x10000", 0, 0 },
+  { "0.1.0xffff", 1, 0x0001ffff },
+*/
+  { "0.1a.3", 0, 0 },
+  { "0.1.a3", 0, 0 },
+  { "1.2.3.4", 1, 0x01020304 },
+  { "0400.2.3.4", 0, 0 },
+  { "1.0x100.3.4", 0, 0 },
+  { "1.2.256.4", 0, 0 },
+  { "1.2.3.0x100", 0, 0 },
+  { "323543357756889", 0, 0 },
+  { "10.1.2.3.4", 0, 0},
+};
+
+
+int
+main (int argc, char *argv[])
+{
+  int result = 0;
+  size_t cnt;
+
+  for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
+    {
+      struct in_addr addr;
+
+      if ((int) inet_aton (tests[cnt].input, &addr) != tests[cnt].valid)
+	{
+	  if (tests[cnt].valid)
+	    printf ("\"%s\" not seen as valid IP address\n", tests[cnt].input);
+	  else
+	    printf ("\"%s\" seen as valid IP address\n", tests[cnt].input);
+	  result = 1;
+	}
+      else if (tests[cnt].valid && addr.s_addr != ntohl (tests[cnt].result))
+	{
+	  printf ("\"%s\" not converted correctly: is %08x, should be %08x\n",
+		  tests[cnt].input, addr.s_addr, tests[cnt].result);
+	  result = 1;
+	}
+    }
+
+  return result;
+}
diff --git a/ap/build/uClibc/test/inet/tst-ether_aton.c b/ap/build/uClibc/test/inet/tst-ether_aton.c
new file mode 100644
index 0000000..67cb435
--- /dev/null
+++ b/ap/build/uClibc/test/inet/tst-ether_aton.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <netinet/ether.h>
+
+static struct tests
+{
+  const char *input;
+  int valid;
+  uint8_t result[6];
+} tests[] =
+{
+  { "", 0, {0, 0, 0, 0, 0, 0} },
+  { "AB:CD:EF:01:23:45", 1, {171, 205, 239, 1, 35, 69} },
+  { "\022B:BB:BB:BB:BB:BB", 0, {0, 0, 0, 0, 0, 0} }
+};
+
+
+int
+main (int argc, char *argv[])
+{
+  int result = 0;
+  size_t cnt;
+
+  for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
+    {
+      struct ether_addr *addr;
+
+      if (!!(addr = ether_aton (tests[cnt].input)) != tests[cnt].valid)
+      {
+        if (tests[cnt].valid)
+          printf ("\"%s\" not seen as valid MAC address\n", tests[cnt].input);
+        else
+          printf ("\"%s\" seen as valid MAC address\n", tests[cnt].input);
+        result = 1;
+      }
+      else if (tests[cnt].valid
+               && memcmp(addr, &tests[cnt].result, sizeof(struct ether_addr)))
+      {
+        printf ("\"%s\" not converted correctly\n", tests[cnt].input);
+        result = 1;
+      }
+    }
+
+  return result;
+}
diff --git a/ap/build/uClibc/test/inet/tst-ethers-line.c b/ap/build/uClibc/test/inet/tst-ethers-line.c
new file mode 100644
index 0000000..19cf2fb
--- /dev/null
+++ b/ap/build/uClibc/test/inet/tst-ethers-line.c
@@ -0,0 +1,54 @@
+#include <netinet/ether.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+/* glibc 2.4 has no ETHER_FILE_NAME, host compile fails without this */
+#ifndef ETHER_FILE_NAME
+#define ETHER_FILE_NAME "/etc/ethers"
+#endif
+
+#define ETHER_LINE_LEN 256
+
+/* This test requires /etc/ethers to exist
+ * and to have nonzero length
+ */
+
+int main(void)
+{
+	struct ether_addr addr;
+	char hostname[ETHER_LINE_LEN];
+	int fd, i;
+	const char *ethers;
+	struct stat statb;
+
+	if ((fd = open(ETHER_FILE_NAME, O_RDONLY)) == -1) {
+		perror ("Cannot open file");
+		exit(1);
+	}
+
+	if (fstat(fd, &statb)) {
+		perror("Stat failed");
+		exit(1);
+	}
+	ethers = mmap(NULL, statb.st_size, PROT_READ, MAP_SHARED, fd, 0);
+
+	if (ethers == MAP_FAILED) {
+		perror("File mapping failed");
+		exit(1);
+	}
+
+	ether_line(ethers, &addr, hostname);
+
+	for (i = 0; i < 6; i++) {
+		printf("%02x", addr.ether_addr_octet[i]);
+		if (i < 5)
+			printf(":");
+	}
+	printf(" %s\n", hostname);
+
+	return 0;
+}
diff --git a/ap/build/uClibc/test/inet/tst-ethers.c b/ap/build/uClibc/test/inet/tst-ethers.c
new file mode 100644
index 0000000..6b6e10c
--- /dev/null
+++ b/ap/build/uClibc/test/inet/tst-ethers.c
@@ -0,0 +1,33 @@
+#include <netinet/ether.h>
+#include <stdio.h>
+
+#define ETHER_LINE_LEN 256
+
+/* This test requires /etc/ethers to exist
+ * and to have host "teeth". For example:
+ * 00:11:22:33:44:55 teeth
+ */
+
+int main(void)
+{
+	struct ether_addr addr;
+	char host[ETHER_LINE_LEN];
+	int i;
+	int res = ether_hostton("teeth", &addr);
+
+	if (res)
+		return 1;
+
+	for (i = 0; i < 6; i++) {
+		printf("%02x", addr.ether_addr_octet[i]);
+		if (i < 5)
+			printf(":");
+	}
+
+	res = ether_ntohost(host, &addr);
+	if (res)
+		return 1;
+	printf(" %s\n", host);
+
+	return 0;
+}
diff --git a/ap/build/uClibc/test/inet/tst-network.c b/ap/build/uClibc/test/inet/tst-network.c
new file mode 100644
index 0000000..2598637
--- /dev/null
+++ b/ap/build/uClibc/test/inet/tst-network.c
@@ -0,0 +1,105 @@
+/* Test for inet_network.
+   Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdio.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+struct
+{
+  const char *network;
+  uint32_t number;
+} tests [] =
+{
+  {"1.0.0.0", 0x1000000},
+  {"1.0.0", 0x10000},
+  {"1.0", 0x100},
+  {"1", 0x1},
+  {"192.168.0.0", 0xC0A80000},
+  /* Now some invalid addresses.  */
+  {"141.30.225.2800", INADDR_NONE},
+  {"141.76.1.1.1", INADDR_NONE},
+  {"141.76.1.11.", INADDR_NONE},
+  {"1410", INADDR_NONE},
+  {"1.1410", INADDR_NONE},
+  {"1.1410.", INADDR_NONE},
+  {"1.1410", INADDR_NONE},
+  {"141.76.1111", INADDR_NONE},
+  {"141.76.1111.", INADDR_NONE},
+  {"1.1.1.257", INADDR_NONE},
+  /* Now some from BSD */
+  {"0x12", 0x00000012},
+  {"127.1", 0x00007f01},
+  {"127.1.2.3", 0x7f010203},
+  {"0x123456", INADDR_NONE},
+  {"0x12.0x34", 0x00001234},
+  {"0x12.0x345", INADDR_NONE},
+  {"1.2.3.4.5", INADDR_NONE},
+  {"1..3.4", INADDR_NONE},
+  {".", INADDR_NONE},
+  {"1.", INADDR_NONE},
+  {".1", INADDR_NONE},
+  {"x", INADDR_NONE},
+  {"0x", INADDR_NONE},
+  {"0", 0x00000000},
+  {"0x0", 0x00000000},
+  {"01.02.07.077", 0x0102073f},
+  {"0x1.23.045.0", 0x01172500},
+  {"", INADDR_NONE},
+  {" ", INADDR_NONE},
+  {"bar", INADDR_NONE},
+  {"1.2bar", INADDR_NONE},
+  {"1.", INADDR_NONE},
+  {"ÊÃÕËÅÎ", INADDR_NONE},
+  {"255.255.255.255", INADDR_NONE},
+  {"x", INADDR_NONE},
+  {"0X12", 0x00000012},
+  {"078", INADDR_NONE},
+  {"1 bar", INADDR_NONE},
+  {"127.0xfff", INADDR_NONE},
+};
+
+
+int
+main (void)
+{
+  int errors = 0;
+  size_t i;
+  uint32_t res;
+
+  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+    {
+      printf ("Testing: %s\n", tests[i].network);
+      res = inet_network (tests[i].network);
+
+      if (res != tests[i].number)
+	{
+	  ++errors;
+	  printf ("Test failed for inet_network (\"%s\"):\n",
+		  tests[i].network);
+	  printf ("Expected return value %u (0x%x) but got %u (0x%x).\n",
+		  tests[i].number, tests[i].number, res, res);
+	}
+
+    }
+
+  return errors != 0;
+}
diff --git a/ap/build/uClibc/test/inet/tst-ntoa.c b/ap/build/uClibc/test/inet/tst-ntoa.c
new file mode 100644
index 0000000..9be91eb
--- /dev/null
+++ b/ap/build/uClibc/test/inet/tst-ntoa.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+
+static int
+test (unsigned int inaddr, const char *expected)
+{
+  struct in_addr addr;
+  char *res;
+  int fail;
+
+  addr.s_addr = htonl (inaddr);
+  res = inet_ntoa (addr);
+  fail = strcmp (res, expected);
+
+  printf ("%#010x -> \"%s\" -> %s%s\n", inaddr, res,
+	  fail ? "fail, expected" : "ok", fail ? expected : "");
+
+  return fail;
+}
+
+
+int
+main (void)
+{
+  int result = 0;
+
+  result |= test (INADDR_LOOPBACK, "127.0.0.1");
+  result |= test (INADDR_BROADCAST, "255.255.255.255");
+  result |= test (INADDR_ANY, "0.0.0.0");
+  result |= test (0xc0060746, "192.6.7.70");
+
+  return result;
+}