summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/inet/bug-if1.c54
-rw-r--r--test/inet/tst-aton.c80
-rw-r--r--test/inet/tst-network.c73
-rw-r--r--test/inet/tst-ntoa.c36
4 files changed, 243 insertions, 0 deletions
diff --git a/test/inet/bug-if1.c b/test/inet/bug-if1.c
new file mode 100644
index 000000000..6bcd175eb
--- /dev/null
+++ b/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/test/inet/tst-aton.c b/test/inet/tst-aton.c
new file mode 100644
index 000000000..3e945f130
--- /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-network.c b/test/inet/tst-network.c
new file mode 100644
index 000000000..428388805
--- /dev/null
+++ b/test/inet/tst-network.c
@@ -0,0 +1,73 @@
+/* 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}
+};
+
+
+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)
+ {
+ 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 000000000..9be91eb51
--- /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;
+}