@@ -414,6 +414,60 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_invalid_nested_start
414414 LT_CHECK_THROW (http::ip_representation(" ::ccff:192.0.5.128" ));
415415LT_END_AUTO_TEST (ip_representation6_str_invalid_nested_starting_wrong_prefix)
416416
417+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_sockaddr)
418+ struct sockaddr_in ip4addr;
419+
420+ ip4addr.sin_family = AF_INET;
421+ ip4addr.sin_port = htons(3490 );
422+ ip4addr.sin_addr.s_addr = inet_addr(" 127.0.0.1" );
423+
424+ http::ip_representation test_ip ((sockaddr*) &ip4addr);
425+
426+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV4);
427+
428+ for (int i = 0 ; i < 12 ; i++) {
429+ LT_CHECK_EQ (test_ip.pieces [i], 0 );
430+ }
431+
432+ LT_CHECK_EQ (test_ip.pieces[12 ], 127 );
433+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
434+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
435+ LT_CHECK_EQ (test_ip.pieces[15 ], 1 );
436+
437+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
438+ LT_END_AUTO_TEST (ip_representation4_sockaddr)
439+
440+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_sockaddr)
441+ struct sockaddr_in6 ip6addr;
442+
443+ ip6addr.sin6_family = AF_INET6;
444+ ip6addr.sin6_port = htons(3490 );
445+ inet_pton (AF_INET6, " 2001:db8:8714:3a90::12" , &(ip6addr.sin6_addr));
446+
447+ http::ip_representation test_ip ((sockaddr*) &ip6addr);
448+
449+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
450+
451+ LT_CHECK_EQ (test_ip.pieces[0 ], 32 );
452+ LT_CHECK_EQ (test_ip.pieces[1 ], 1 );
453+ LT_CHECK_EQ (test_ip.pieces[2 ], 13 );
454+ LT_CHECK_EQ (test_ip.pieces[3 ], 184 );
455+ LT_CHECK_EQ (test_ip.pieces[4 ], 135 );
456+ LT_CHECK_EQ (test_ip.pieces[5 ], 20 );
457+ LT_CHECK_EQ (test_ip.pieces[6 ], 58 );
458+ LT_CHECK_EQ (test_ip.pieces[7 ], 144 );
459+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
460+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
461+ LT_CHECK_EQ (test_ip.pieces[10 ], 0 );
462+ LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
463+ LT_CHECK_EQ (test_ip.pieces[12 ], 0 );
464+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
465+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
466+ LT_CHECK_EQ (test_ip.pieces[15 ], 18 );
467+
468+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
469+ LT_END_AUTO_TEST (ip_representation6_sockaddr)
470+
417471LT_BEGIN_AUTO_TEST_ENV()
418472 AUTORUN_TESTS()
419473LT_END_AUTO_TEST_ENV()
0 commit comments