1 /* $Id: inet_aton-t.c 5061 2001-12-12 09:21:17Z rra $ */
2 /* inet_aton test suite. */
6 #include <netinet/in.h>
8 int test_inet_aton(const char *, struct in_addr *);
11 test_addr(int n, const char *string, unsigned long addr)
16 success = test_inet_aton(string, &in);
17 okay = (success && in.s_addr == htonl(addr));
19 printf("%sok %d\n", okay ? "" : "not ", n);
20 if (!okay && !success) printf(" success: %d\n", success);
21 if (!okay && in.s_addr != htonl(addr))
22 printf(" want: %lx\n saw: %lx\n", (unsigned long) htonl(addr),
23 (unsigned long) in.s_addr);
27 test_fail(int n, const char *string)
32 in.s_addr = htonl(0x01020304UL);
33 success = test_inet_aton(string, &in);
34 success = (success == 0 && in.s_addr == htonl(0x01020304UL));
35 printf("%sok %d\n", success ? "" : "not ", n);
43 test_addr( 1, "0.0.0.0", 0);
44 test_addr( 2, "127.0.0.000000", 0x7f000000UL);
45 test_addr( 3, "255.255.255.255", 0xffffffffUL);
46 test_addr( 4, "172.200.232.199", 0xacc8e8c7UL);
47 test_addr( 5, "1.2.3.4", 0x01020304UL);
49 test_addr( 6, "0x0.0x0.0x0.0x0", 0);
50 test_addr( 7, "0x7f.0x000.0x0.0x00", 0x7f000000UL);
51 test_addr( 8, "0xff.0xFf.0xFF.0xff", 0xffffffffUL);
52 test_addr( 9, "0xAC.0xc8.0xe8.0xC7", 0xacc8e8c7UL);
53 test_addr(10, "0xAa.0xbB.0xCc.0xdD", 0xaabbccddUL);
54 test_addr(11, "0xEe.0xfF.0.0x00000", 0xeeff0000UL);
55 test_addr(12, "0x1.0x2.0x00003.0x4", 0x01020304UL);
57 test_addr(13, "000000.00.000.00", 0);
58 test_addr(14, "0177.0", 0x7f000000UL);
59 test_addr(15, "0377.0377.0377.0377", 0xffffffffUL);
60 test_addr(16, "0254.0310.0350.0307", 0xacc8e8c7UL);
61 test_addr(17, "00001.02.3.00000004", 0x01020304UL);
63 test_addr(18, "16909060", 0x01020304UL);
64 test_addr(19, "172.062164307", 0xacc8e8c7UL);
65 test_addr(20, "172.0xc8.0xe8c7", 0xacc8e8c7UL);
66 test_addr(21, "127.1", 0x7f000001UL);
67 test_addr(22, "0xffffffff", 0xffffffffUL);
68 test_addr(23, "127.0xffffff", 0x7fffffffUL);
69 test_addr(24, "127.127.0xffff", 0x7f7fffffUL);
72 test_fail(26, "Donald Duck!");
73 test_fail(27, "a127.0.0.1");
74 test_fail(28, "aaaabbbb");
75 test_fail(29, "0x100000000");
76 test_fail(30, "0xfffffffff");
77 test_fail(31, "127.0xfffffff");
78 test_fail(32, "127.376926742");
79 test_fail(33, "127.127.01452466");
80 test_fail(34, "127.127.127.0x100");
81 test_fail(35, "256.0");
82 test_fail(36, "127.0378.127.127");
83 test_fail(37, "127.127.0x100.127");
84 test_fail(38, "127.0.o.1");
85 test_fail(39, "127.127.127.127v");
86 test_fail(40, "ef.127.127.127");
87 test_fail(41, "0128.127.127.127");
88 test_fail(42, "0xeg.127");
89 test_fail(43, ".127.127");
90 test_fail(44, "127.127.");
91 test_fail(45, "127..127");
92 test_fail(46, "de.ad.be.ef");