@@ -302,6 +302,38 @@ static void test_in_addr_ifindex_name_from_string_auto(void) {
302302 test_in_addr_ifindex_name_from_string_auto_one ("fe80::18%19#another.test.com" , "another.test.com" );
303303}
304304
305+ static void test_in_addr_port_ifindex_name_from_string_auto_one (const char * str , int family , uint16_t port , int ifindex , const char * server_name ) {
306+ _cleanup_free_ char * name = NULL , * x = NULL ;
307+ union in_addr_union a ;
308+ uint16_t p ;
309+ int f , i ;
310+
311+ assert_se (in_addr_port_ifindex_name_from_string_auto (str , & f , & a , & p , & i , & name ) >= 0 );
312+ assert_se (family == f );
313+ assert_se (port == p );
314+ assert_se (ifindex == i );
315+ assert_se (streq_ptr (server_name , name ));
316+ assert_se (in_addr_port_ifindex_name_to_string (f , & a , p , i , name , & x ) >= 0 );
317+ assert_se (streq (str , x ));
318+ }
319+
320+ static void test_in_addr_port_ifindex_name_from_string_auto (void ) {
321+ log_info ("/* %s */" , __func__ );
322+
323+ test_in_addr_port_ifindex_name_from_string_auto_one ("192.168.0.1" , AF_INET , 0 , 0 , NULL );
324+ test_in_addr_port_ifindex_name_from_string_auto_one ("192.168.0.1#test.com" , AF_INET , 0 , 0 , "test.com" );
325+ test_in_addr_port_ifindex_name_from_string_auto_one ("192.168.0.1:53" , AF_INET , 53 , 0 , NULL );
326+ test_in_addr_port_ifindex_name_from_string_auto_one ("192.168.0.1:53#example.com" , AF_INET , 53 , 0 , "example.com" );
327+ test_in_addr_port_ifindex_name_from_string_auto_one ("fe80::18" , AF_INET6 , 0 , 0 , NULL );
328+ test_in_addr_port_ifindex_name_from_string_auto_one ("fe80::18#hoge.com" , AF_INET6 , 0 , 0 , "hoge.com" );
329+ test_in_addr_port_ifindex_name_from_string_auto_one ("fe80::18%19" , AF_INET6 , 0 , 19 , NULL );
330+ test_in_addr_port_ifindex_name_from_string_auto_one ("[fe80::18]:53" , AF_INET6 , 53 , 0 , NULL );
331+ test_in_addr_port_ifindex_name_from_string_auto_one ("fe80::18%19#hoge.com" , AF_INET6 , 0 , 19 , "hoge.com" );
332+ test_in_addr_port_ifindex_name_from_string_auto_one ("[fe80::18]:53#hoge.com" , AF_INET6 , 53 , 0 , "hoge.com" );
333+ test_in_addr_port_ifindex_name_from_string_auto_one ("[fe80::18]:53%19" , AF_INET6 , 53 , 19 , NULL );
334+ test_in_addr_port_ifindex_name_from_string_auto_one ("[fe80::18]:53%19#hoge.com" , AF_INET6 , 53 , 19 , "hoge.com" );
335+ }
336+
305337static void test_sockaddr_equal (void ) {
306338 union sockaddr_union a = {
307339 .in .sin_family = AF_INET ,
@@ -735,6 +767,7 @@ int main(int argc, char *argv[]) {
735767 test_in_addr_ifindex_to_string ();
736768 test_in_addr_ifindex_from_string_auto ();
737769 test_in_addr_ifindex_name_from_string_auto ();
770+ test_in_addr_port_ifindex_name_from_string_auto ();
738771
739772 test_sockaddr_equal ();
740773
0 commit comments