about summary refs log tree commit diff
path: root/resolv/tst-aton.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-10-02 16:34:45 +0000
committerUlrich Drepper <drepper@redhat.com>1999-10-02 16:34:45 +0000
commit81ca53df7dea9967eeb56d47376e0f3fd2c9edda (patch)
tree4a2fb76f4990141862cc43093c2cc7e1fab56d04 /resolv/tst-aton.c
parenta465f6bdd2a7a1f79083fec65c3eeff093451e9e (diff)
downloadglibc-81ca53df7dea9967eeb56d47376e0f3fd2c9edda.tar.gz
glibc-81ca53df7dea9967eeb56d47376e0f3fd2c9edda.tar.xz
glibc-81ca53df7dea9967eeb56d47376e0f3fd2c9edda.zip
Update.
1999-10-02  Ulrich Drepper  <drepper@cygnus.com>

	* resolv/tst-aton.c (main): Add more tests.

	* resolv/inet_addr.c (inet_aton): Correct some problems with to
	large numbers.  Optimize a bit.
Diffstat (limited to 'resolv/tst-aton.c')
-rw-r--r--resolv/tst-aton.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/resolv/tst-aton.c b/resolv/tst-aton.c
index 818f9ed61b..79077b00c3 100644
--- a/resolv/tst-aton.c
+++ b/resolv/tst-aton.c
@@ -3,19 +3,69 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-enum { buf_size = 16 };
-static char buf[buf_size] = "323543357756889";
+
+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 },
+};
+
 
 int
 main (int argc, char *argv[])
 {
-  struct in_addr addr;
   int result = 0;
+  int cnt;
 
-  if (inet_aton (buf, &addr) != 0)
+  for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
     {
-      printf ("%s is seen as a valid IP address\n", buf);
-      result = 1;
+      struct in_addr addr;
+
+      if (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;