@@ -255,15 +255,63 @@ void test_getaddrinfo_no_host(void)
255255 freeaddrinfo (res );
256256}
257257
258+ void test_getaddrinfo_num_ipv4 (void )
259+ {
260+ struct zsock_addrinfo * res = NULL ;
261+ struct sockaddr_in * saddr ;
262+ int ret ;
263+
264+ ret = zsock_getaddrinfo ("1.2.3.255" , "65534" , NULL , & res );
265+
266+ zassert_equal (ret , 0 , "Invalid result" );
267+ zassert_not_null (res , "" );
268+ zassert_is_null (res -> ai_next , "" );
269+
270+ zassert_equal (res -> ai_family , AF_INET , "" );
271+ zassert_equal (res -> ai_socktype , SOCK_STREAM , "" );
272+ zassert_equal (res -> ai_protocol , IPPROTO_TCP , "" );
273+
274+ saddr = (struct sockaddr_in * )res -> ai_addr ;
275+ zassert_equal (saddr -> sin_family , AF_INET , "" );
276+ zassert_equal (saddr -> sin_port , htons (65534 ), "" );
277+ zassert_equal (saddr -> sin_addr .s4_addr [0 ], 1 , "" );
278+ zassert_equal (saddr -> sin_addr .s4_addr [1 ], 2 , "" );
279+ zassert_equal (saddr -> sin_addr .s4_addr [2 ], 3 , "" );
280+ zassert_equal (saddr -> sin_addr .s4_addr [3 ], 255 , "" );
281+
282+ zsock_freeaddrinfo (res );
283+ }
284+
285+ void test_getaddrinfo_flags_numerichost (void )
286+ {
287+ int ret ;
288+ struct zsock_addrinfo * res = NULL ;
289+ struct zsock_addrinfo hints = {
290+ .ai_flags = AI_NUMERICHOST ,
291+ };
292+
293+ ret = zsock_getaddrinfo ("foo.bar" , "65534" , & hints , & res );
294+ zassert_equal (ret , DNS_EAI_FAIL , "Invalid result" );
295+ zassert_is_null (res , "" );
296+
297+ ret = zsock_getaddrinfo ("1.2.3.4" , "65534" , & hints , & res );
298+ zassert_equal (ret , 0 , "Invalid result" );
299+ zassert_not_null (res , "" );
300+
301+ zsock_freeaddrinfo (res );
302+ }
303+
258304void test_main (void )
259305{
260306 k_thread_system_pool_assign (k_current_get ());
261307
262308 ztest_test_suite (socket_getaddrinfo ,
263309 ztest_unit_test (test_getaddrinfo_setup ),
264- ztest_user_unit_test (test_getaddrinfo_ok ),
265- ztest_user_unit_test (test_getaddrinfo_cancelled ),
266- ztest_user_unit_test (test_getaddrinfo_no_host ));
310+ ztest_unit_test (test_getaddrinfo_ok ),
311+ ztest_unit_test (test_getaddrinfo_cancelled ),
312+ ztest_unit_test (test_getaddrinfo_no_host ),
313+ ztest_unit_test (test_getaddrinfo_num_ipv4 ),
314+ ztest_unit_test (test_getaddrinfo_flags_numerichost ));
267315
268316 ztest_run_test_suite (socket_getaddrinfo );
269317}
0 commit comments