@ -26,6 +26,7 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
int main ( void )
int main ( void )
{
{
struct wireaddr addr ;
tal_t * ctx = tal_tmpctx ( NULL ) ;
tal_t * ctx = tal_tmpctx ( NULL ) ;
char * ip ;
char * ip ;
u16 port ;
u16 port ;
@ -35,6 +36,10 @@ int main(void)
assert ( streq ( ip , " ::1 " ) ) ;
assert ( streq ( ip , " ::1 " ) ) ;
assert ( port = = 80 ) ;
assert ( port = = 80 ) ;
assert ( ! parse_ip_port ( ctx , " ip6-localhost " , & ip , & port ) ) ;
assert ( streq ( ip , " ip6-localhost " ) ) ;
assert ( port = = 0 ) ;
assert ( ! parse_ip_port ( ctx , " ::1 " , & ip , & port ) ) ;
assert ( ! parse_ip_port ( ctx , " ::1 " , & ip , & port ) ) ;
assert ( streq ( ip , " ::1 " ) ) ;
assert ( streq ( ip , " ::1 " ) ) ;
assert ( port = = 0 ) ;
assert ( port = = 0 ) ;
@ -47,6 +52,33 @@ int main(void)
assert ( streq ( ip , " 192.168.2.255 " ) ) ;
assert ( streq ( ip , " 192.168.2.255 " ) ) ;
assert ( port = = 0 ) ;
assert ( port = = 0 ) ;
// unusual but possibly valid case
assert ( ! parse_ip_port ( ctx , " [::1] " , & ip , & port ) ) ;
assert ( streq ( ip , " ::1 " ) ) ;
assert ( port = = 0 ) ;
// service names not supported yet
assert ( ! parse_ip_port ( ctx , " [::1]:http " , & ip , & port ) ) ;
assert ( streq ( ip , " ::1 " ) ) ;
assert ( port = = 0 ) ;
// localhost hostnames for backward compat
parse_wireaddr ( " localhost " , & addr , 200 ) ;
assert ( addr . port = = 200 ) ;
// string should win the port battle
parse_wireaddr ( " [::1]:9735 " , & addr , 500 ) ;
assert ( addr . port = = 9735 ) ;
ip = fmt_wireaddr ( ctx , & addr ) ;
assert ( streq ( ip , " [::1]:9735 " ) ) ;
// should use argument if we have no port in string
parse_wireaddr ( " 2001:db8:85a3::8a2e:370:7334 " , & addr , 9777 ) ;
assert ( addr . port = = 9777 ) ;
ip = fmt_wireaddr ( ctx , & addr ) ;
assert ( streq ( ip , " [2001:db8:85a3::8a2e:370:7334]:9777 " ) ) ;
tal_free ( ctx ) ;
tal_free ( ctx ) ;
return 0 ;
return 0 ;
}
}