@@ -274,6 +274,37 @@ ipv6address_t ipv6address_add(ipv6address_t lhs, ipv6address_t rhs) {
274274
275275
276276int ipv6address_selftest (void )
277+ {
278+ struct test_pair {
279+ const char * name ; // Human-readable IPv6 address string
280+ struct ipaddress ip_addr ; // IP address (union)
281+ };
282+ /* Probably overkill, added while investigating issue #796 */
283+ struct test_pair tests [] = {
284+ {"2001:db8:ac10:fe01::2" , {.ipv6 = {0x20010db8ac10fe01 , 0x0000000000000002 }, .version = 6 }},
285+ {"2607:f8b0:4000::1" , {.ipv6 = {0x2607f8b040000000 , 0x0000000000000001 }, .version = 6 }},
286+ {"fd12:3456:7890:abcd:ef00::1" , {.ipv6 = {0xfd1234567890abcd , 0xef00000000000001 }, .version = 6 }},
287+ {"::1" , {.ipv6 = {0x0000000000000000 , 0x0000000000000001 }, .version = 6 }},
288+ {"1::" , {.ipv6 = {0x0001000000000000 , 0x0000000000000000 }, .version = 6 }},
289+ {"1::2" , {.ipv6 = {0x0001000000000000 , 0x0000000000000002 }, .version = 6 }},
290+ {"2::1" , {.ipv6 = {0x0002000000000000 , 0x0000000000000001 }, .version = 6 }},
291+ {"1:2::" , {.ipv6 = {0x0001000200000000 , 0x0000000000000000 }, .version = 6 }},
292+ {NULL , {{0 , 0 }, 0 }}
293+ };
294+
295+ int x = 0 ;
296+ ipaddress ip ;
297+ struct ipaddress_formatted fmt ;
298+
299+ for (int i = 0 ; tests [i ].name != NULL ; i ++ ) {
300+ fmt = ipaddress_fmt (tests [i ].ip_addr );
301+ if (strcmp (fmt .string , tests [i ].name ) != 0 )
302+ x ++ ;
303+ }
304+ return x ;
305+ }
306+
307+ int ipv4address_selftest (void )
277308{
278309 int x = 0 ;
279310 ipaddress ip ;
0 commit comments