summaryrefslogtreecommitdiff
path: root/test/inet
diff options
context:
space:
mode:
Diffstat (limited to 'test/inet')
-rw-r--r--test/inet/Makefile8
-rw-r--r--test/inet/Makefile.in17
-rw-r--r--test/inet/bug-if1.c53
-rw-r--r--test/inet/gethost.c40
-rw-r--r--test/inet/gethost_r-align.c50
-rw-r--r--test/inet/gethostid.c6
-rw-r--r--test/inet/getnetent.c17
-rw-r--r--test/inet/if_nameindex.c61
-rw-r--r--test/inet/tst-aton.c80
-rw-r--r--test/inet/tst-ether_aton.c46
-rw-r--r--test/inet/tst-ethers-line.c55
-rw-r--r--test/inet/tst-ethers.c37
-rw-r--r--test/inet/tst-ifaddrs.c99
-rw-r--r--test/inet/tst-network.c104
-rw-r--r--test/inet/tst-ntoa.c36
-rw-r--r--test/inet/tst-res.c44
-rw-r--r--test/inet/tst-sock-nonblock.c53
17 files changed, 806 insertions, 0 deletions
diff --git a/test/inet/Makefile b/test/inet/Makefile
new file mode 100644
index 0000000..b294ea6
--- /dev/null
+++ b/test/inet/Makefile
@@ -0,0 +1,8 @@
+# uClibc inet tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+top_builddir=../../
+top_srcdir=../../
+include ../Rules.mak
+-include Makefile.in
+include ../Test.mak
diff --git a/test/inet/Makefile.in b/test/inet/Makefile.in
new file mode 100644
index 0000000..31a4837
--- /dev/null
+++ b/test/inet/Makefile.in
@@ -0,0 +1,17 @@
+# 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 test-ifaddrs
+endif
+
+ifeq ($(UCLIBC_HAS_SOCKET)$(UCLIBC_HAS_IPV4)$(UCLIBC_HAS_IPV6),)
+TESTS_DISABLED += tst-ether_aton tst-ethers tst-ethers-line
+endif
+
+ifeq ($(UCLIBC_HAS_RESOLVER_SUPPORT),)
+TESTS_DISABLED += tst-res
+else
+LDFLAGS_tst-res_glibc := -lresolv # assume it's glibc or somebody with that lib
+endif
diff --git a/test/inet/bug-if1.c b/test/inet/bug-if1.c
new file mode 100644
index 0000000..ea84a68
--- /dev/null
+++ b/test/inet/bug-if1.c
@@ -0,0 +1,53 @@
+/* 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#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/test/inet/gethost.c b/test/inet/gethost.c
new file mode 100644
index 0000000..77467e9
--- /dev/null
+++ b/test/inet/gethost.c
@@ -0,0 +1,40 @@
+#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(void)
+{
+ in_addr_t addr = inet_addr("127.0.0.1");
+ struct hostent *hent;
+
+ hent = gethostent();
+ if (hent == NULL) {
+ printf("gethostent(%d):%s\n", errno, hstrerror(h_errno));
+ exit(1);
+ }
+
+ hent = gethostbyname("localhost");
+ if (hent == NULL) {
+ printf("gethostbyname(%d):%s\n", errno, hstrerror(h_errno));
+ exit(1);
+ }
+
+ hent = gethostbyname2("localhost", AF_INET);
+ if (hent == NULL) {
+ printf("gethostbyname2(%d):%s\n", errno, hstrerror(h_errno));
+ exit(1);
+ }
+
+ hent = gethostbyaddr(&addr, sizeof(addr), AF_INET);
+ if (hent == NULL) {
+ printf("gethostbyaddr(%d):%s\n", errno, hstrerror(h_errno));
+ exit(1);
+ }
+
+ return 0;
+}
+
diff --git a/test/inet/gethost_r-align.c b/test/inet/gethost_r-align.c
new file mode 100644
index 0000000..53ce93a
--- /dev/null
+++ b/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/test/inet/gethostid.c b/test/inet/gethostid.c
new file mode 100644
index 0000000..1b9af86
--- /dev/null
+++ b/test/inet/gethostid.c
@@ -0,0 +1,6 @@
+#include <unistd.h>
+#include <stdio.h>
+int main(void) {
+ printf("hostid=%ld\n", gethostid());
+ return 0;
+}
diff --git a/test/inet/getnetent.c b/test/inet/getnetent.c
new file mode 100644
index 0000000..1f55e43
--- /dev/null
+++ b/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("%u.%u.%u.%u\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/test/inet/if_nameindex.c b/test/inet/if_nameindex.c
new file mode 100644
index 0000000..126c5ba
--- /dev/null
+++ b/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/test/inet/tst-aton.c b/test/inet/tst-aton.c
new file mode 100644
index 0000000..3e945f1
--- /dev/null
+++ b/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/test/inet/tst-ether_aton.c b/test/inet/tst-ether_aton.c
new file mode 100644
index 0000000..67cb435
--- /dev/null
+++ b/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/test/inet/tst-ethers-line.c b/test/inet/tst-ethers-line.c
new file mode 100644
index 0000000..182faf0
--- /dev/null
+++ b/test/inet/tst-ethers-line.c
@@ -0,0 +1,55 @@
+#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. You should create it manually,
+ * if it doesn't exist.
+ */
+
+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 /etc/ethers");
+ 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/test/inet/tst-ethers.c b/test/inet/tst-ethers.c
new file mode 100644
index 0000000..f12813a
--- /dev/null
+++ b/test/inet/tst-ethers.c
@@ -0,0 +1,37 @@
+#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
+ * You should create /etc/ethers file with
+ * host "teeth" manually, if it doesn't exist.
+ */
+
+int main(void)
+{
+ struct ether_addr addr;
+ char host[ETHER_LINE_LEN];
+ int i;
+ int res = ether_hostton("teeth", &addr);
+
+ if (res) {
+ printf("Either /etc/ethers is missing or it has incorrect contents\n");
+ 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/test/inet/tst-ifaddrs.c b/test/inet/tst-ifaddrs.c
new file mode 100644
index 0000000..6e6c015
--- /dev/null
+++ b/test/inet/tst-ifaddrs.c
@@ -0,0 +1,99 @@
+/* Test listing of network interface addresses.
+ Copyright (C) 2002-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ifaddrs.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+static int failures;
+
+static const char *
+addr_string (struct sockaddr *sa, char *buf, size_t size)
+{
+ if (sa == NULL)
+ return "<none>";
+
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ return inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr,
+ buf, size);
+ case AF_INET6:
+ return inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr,
+ buf, size);
+#ifdef AF_LINK
+ case AF_LINK:
+ return "<link>";
+#endif
+ case AF_UNSPEC:
+ return "---";
+
+#ifdef AF_PACKET
+ case AF_PACKET:
+ return "<packet>";
+#endif
+
+ default:
+ ++failures;
+ printf ("sa_family=%d %08x\n", sa->sa_family,
+ *(int*)&((struct sockaddr_in *) sa)->sin_addr.s_addr);
+ return "<unexpected sockaddr family>";
+ }
+}
+
+
+static int
+do_test (void)
+{
+ struct ifaddrs *ifaces, *ifa;
+
+ if (getifaddrs (&ifaces) < 0)
+ {
+ if (errno != ENOSYS)
+ {
+ printf ("Couldn't get any interfaces: %s.\n", strerror (errno));
+ exit (1);
+ }
+ /* The function is simply not implemented. */
+ exit (0);
+ }
+
+ puts ("\
+Name Flags Address Netmask Broadcast/Destination");
+
+ for (ifa = ifaces; ifa != NULL; ifa = ifa->ifa_next)
+ {
+ char abuf[64], mbuf[64], dbuf[64];
+ printf ("%-15s%#.4x %-15s %-15s %-15s\n",
+ ifa->ifa_name, ifa->ifa_flags,
+ addr_string (ifa->ifa_addr, abuf, sizeof (abuf)),
+ addr_string (ifa->ifa_netmask, mbuf, sizeof (mbuf)),
+ addr_string (ifa->ifa_broadaddr, dbuf, sizeof (dbuf)));
+ }
+
+ freeifaddrs (ifaces);
+
+ return failures ? 1 : 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/inet/tst-network.c b/test/inet/tst-network.c
new file mode 100644
index 0000000..c6089aa
--- /dev/null
+++ b/test/inet/tst-network.c
@@ -0,0 +1,104 @@
+/* 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#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/test/inet/tst-ntoa.c b/test/inet/tst-ntoa.c
new file mode 100644
index 0000000..9be91eb
--- /dev/null
+++ b/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;
+}
diff --git a/test/inet/tst-res.c b/test/inet/tst-res.c
new file mode 100644
index 0000000..b65f30f
--- /dev/null
+++ b/test/inet/tst-res.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+#include <netdb.h>
+
+int main(int argc, char **argv)
+{
+ int r;
+ struct __res_state state;
+
+ r = res_ninit(&state);
+ if (r) {
+ herror("ninit");
+ abort();
+ }
+ r = res_init();
+ if (r) {
+ herror("init");
+ abort();
+ }
+
+#ifdef __UCLIBC_HAS_BSD_RES_CLOSE__
+ res_close();
+#endif
+#ifdef __UCLIBC__
+ /* assume there is at least one resolver configured */
+ assert (state._u._ext.nscount > 0);
+#else
+ assert (state._u._ext.nscount == 0);
+#endif
+ assert (state.options & RES_INIT);
+ res_nclose(&state);
+#ifdef __UCLIBC__
+ /* We wipe the whole thing */
+ assert ((state.options & RES_INIT) == 0);
+#endif
+ assert (state._u._ext.nscount == 0);
+
+ return 0;
+}
+
diff --git a/test/inet/tst-sock-nonblock.c b/test/inet/tst-sock-nonblock.c
new file mode 100644
index 0000000..54a7ee2
--- /dev/null
+++ b/test/inet/tst-sock-nonblock.c
@@ -0,0 +1,53 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * Nonblocking socket test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <error.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/fcntl.h>
+
+static int
+do_test(void)
+{
+ int fd, ret, result = 0;
+ struct sockaddr_un sa;
+ char buf;
+
+ fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+ if (fd < 0) {
+ perror("socket()");
+ result = 1;
+ }
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sun_family = AF_UNIX;
+ strcpy(sa.sun_path, "socktest");
+ unlink("socktest");
+ if (bind(fd, (const struct sockaddr *)&sa, sizeof(sa)) < 0) {
+ perror("bind()");
+ result = 1;
+ }
+
+ ret = read(fd, &buf, sizeof(buf));
+ if (ret != -1 || errno != EAGAIN) {
+ error(0, 0, "Nonblocking read returned %d", ret);
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"