2 #include "ntp_stdlib.h"
3 #include "sockaddrtest.h"
8 extern void test_IPv4AddressOnly(void);
9 extern void test_IPv4AddressWithPort(void);
10 //#ifdef ISC_PLATFORM_HAVEIPV6
11 extern void test_IPv6AddressOnly(void);
12 extern void test_IPv6AddressWithPort(void);
13 //#endif /* ISC_PLATFORM_HAVEIPV6 */
14 extern void test_IllegalAddress(void);
15 extern void test_IllegalCharInPort(void);
28 test_IPv4AddressOnly(void) {
29 const char *str = "192.0.2.1";
33 expected.sa4.sin_family = AF_INET;
34 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
35 SET_PORT(&expected, NTP_PORT);
37 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
38 TEST_ASSERT_TRUE(IsEqual(expected, actual));
42 test_IPv4AddressWithPort(void) {
43 const char *str = "192.0.2.2:2000";
47 expected.sa4.sin_family = AF_INET;
48 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.2");
49 SET_PORT(&expected, 2000);
51 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
52 TEST_ASSERT_TRUE(IsEqual(expected, actual));
57 test_IPv6AddressOnly(void) {
59 //#ifdef ISC_PLATFORM_HAVEIPV6 //looks like HAVEIPV6 checks if system has IPV6 capabilies. WANTIPV6 can be changed with build --disable-ipv6
60 #ifdef ISC_PLATFORM_WANTIPV6
61 const struct in6_addr address = {
62 0x20, 0x01, 0x0d, 0xb8,
63 0x85, 0xa3, 0x08, 0xd3,
64 0x13, 0x19, 0x8a, 0x2e,
65 0x03, 0x70, 0x73, 0x34
68 const char *str = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
72 expected.sa6.sin6_family = AF_INET6;
73 expected.sa6.sin6_addr = address;
74 SET_PORT(&expected, NTP_PORT);
76 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
77 TEST_ASSERT_TRUE(IsEqual(expected, actual));
80 TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
81 #endif /* ISC_PLATFORM_HAVEIPV6 */
89 test_IPv6AddressWithPort(void) {
91 #ifdef ISC_PLATFORM_WANTIPV6
93 const struct in6_addr address = {
94 0x20, 0x01, 0x0d, 0xb8,
95 0x85, 0xa3, 0x08, 0xd3,
96 0x13, 0x19, 0x8a, 0x2e,
97 0x03, 0x70, 0x73, 0x34
100 const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]:3000";
104 expected.sa6.sin6_family = AF_INET6;
105 expected.sa6.sin6_addr = address;
106 SET_PORT(&expected, 3000);
108 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
109 TEST_ASSERT_TRUE(IsEqual(expected, actual));
112 TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
113 #endif /* ISC_PLATFORM_HAVEIPV6 */
118 test_IllegalAddress(void) {
119 const char *str = "192.0.2.270:2000";
122 TEST_ASSERT_FALSE(decodenetnum(str, &actual));
126 test_IllegalCharInPort(void) {
127 /* An illegal port does not make the decodenetnum fail, but instead
128 * makes it use the standard port.
130 const char *str = "192.0.2.1:a700";
134 expected.sa4.sin_family = AF_INET;
135 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
136 SET_PORT(&expected, NTP_PORT);
138 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
139 TEST_ASSERT_TRUE(IsEqual(expected, actual));