Removed dependency on inet_aton

Implemented inetPton as a replacement of inet_aton. inetPton is
implemented using net::getBinAddr.

This change fixes bug#3525424.
This commit is contained in:
Tatsuhiro Tsujikawa 2012-05-14 01:17:50 +09:00
parent 06405ce97b
commit ca60020fa4
8 changed files with 68 additions and 168 deletions

View file

@ -15,6 +15,7 @@ class SocketCoreTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testWriteAndReadDatagram);
CPPUNIT_TEST(testGetSocketError);
CPPUNIT_TEST(testInetNtop);
CPPUNIT_TEST(testInetPton);
CPPUNIT_TEST(testGetBinAddr);
CPPUNIT_TEST(testVerifyHostname);
CPPUNIT_TEST_SUITE_END();
@ -26,6 +27,7 @@ public:
void testWriteAndReadDatagram();
void testGetSocketError();
void testInetNtop();
void testInetPton();
void testGetBinAddr();
void testVerifyHostname();
};
@ -108,6 +110,29 @@ void SocketCoreTest::testInetNtop()
}
}
void SocketCoreTest::testInetPton()
{
{
const char ipaddr[] = "192.168.0.1";
uint32_t ans;
CPPUNIT_ASSERT_EQUAL((size_t)4, net::getBinAddr(&ans, ipaddr));
in_addr dest;
CPPUNIT_ASSERT_EQUAL(0, inetPton(AF_INET, ipaddr, &dest));
CPPUNIT_ASSERT(ans == dest.s_addr);
}
{
const char ipaddr[] = "2001:db8::2:1";
unsigned char ans[16];
CPPUNIT_ASSERT_EQUAL((size_t)16, net::getBinAddr(ans, ipaddr));
in6_addr dest;
CPPUNIT_ASSERT_EQUAL(0, inetPton(AF_INET6, ipaddr, &dest));
CPPUNIT_ASSERT(memcmp(ans, &dest, sizeof(ans)) == 0);
}
unsigned char dest[16];
CPPUNIT_ASSERT_EQUAL(-1, inetPton(AF_INET, "localhost", &dest));
CPPUNIT_ASSERT_EQUAL(-1, inetPton(AF_INET6, "localhost", &dest));
}
void SocketCoreTest::testGetBinAddr()
{
unsigned char dest[16];