summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authorbradnelson@google.com <bradnelson@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 05:11:02 +0000
committerbradnelson@google.com <bradnelson@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 05:11:02 +0000
commit6b4656a5ad5a9924b19d8ea2733f2b800891d2c7 (patch)
treeda70158e6c354781137c9d02f85550da1d45aa10 /native_client_sdk
parent08230555e497c5d5f50c03c1703636943c143497 (diff)
downloadchromium_src-6b4656a5ad5a9924b19d8ea2733f2b800891d2c7.zip
chromium_src-6b4656a5ad5a9924b19d8ea2733f2b800891d2c7.tar.gz
chromium_src-6b4656a5ad5a9924b19d8ea2733f2b800891d2c7.tar.bz2
Handle h_addr in a more libc independent way.
Which glibc defines h_addr as a macro to h_addr_list[0], newlib has a separate h_addr member in struct hostent. To correctly handle this, h_addr should be set to match h_addr_list[0]. BUG=None R=binji@chromium.org TEST=bots Review URL: https://codereview.chromium.org/275533002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/libraries/nacl_io/host_resolver.cc11
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc12
2 files changed, 21 insertions, 2 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/host_resolver.cc b/native_client_sdk/src/libraries/nacl_io/host_resolver.cc
index b0a3f24..0ff582c 100644
--- a/native_client_sdk/src/libraries/nacl_io/host_resolver.cc
+++ b/native_client_sdk/src/libraries/nacl_io/host_resolver.cc
@@ -196,6 +196,13 @@ struct hostent* HostResolver::gethostbyname(const char* name) {
}
freeaddrinfo(ai);
+
+#if !defined(h_addr)
+ // Copy element zero of h_addr_list to h_addr when h_addr is not defined
+ // as in some libc's h_addr may be a separate member instead of a macro.
+ hostent_.h_addr = hostent_.h_addr_list[0];
+#endif
+
return &hostent_;
}
@@ -416,6 +423,10 @@ void HostResolver::hostent_cleanup() {
hostent_.h_name = NULL;
hostent_.h_aliases = NULL;
hostent_.h_addr_list = NULL;
+#if !defined(h_addr)
+ // Initialize h_addr separately in the case where it is not a macro.
+ hostent_.h_addr = NULL;
+#endif
}
} // namespace nacl_io
diff --git a/native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc b/native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc
index b5810c0..ec196ff 100644
--- a/native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc
@@ -321,8 +321,12 @@ TEST_F(FakeHostResolverTest, Gethostbyname) {
in_addr_t** addr_list = reinterpret_cast<in_addr_t**>(host->h_addr_list);
ASSERT_NE(reinterpret_cast<in_addr_t**>(NULL), addr_list);
ASSERT_EQ(NULL, addr_list[1]);
- in_addr_t exptected_addr = htonl(FAKE_IP);
- ASSERT_EQ(exptected_addr, *addr_list[0]);
+ in_addr_t expected_addr = htonl(FAKE_IP);
+ ASSERT_EQ(expected_addr, *addr_list[0]);
+ // Check that h_addr also matches as in some libc's it may be a separate
+ // member.
+ in_addr_t* first_addr = reinterpret_cast<in_addr_t*>(host->h_addr);
+ ASSERT_EQ(expected_addr, *first_addr);
}
TEST_F(FakeHostResolverTest, Gethostbyname_Failure) {
@@ -346,6 +350,10 @@ TEST_F(HostResolverTest, Gethostbyname_Numeric) {
ASSERT_NE(reinterpret_cast<in_addr_t**>(NULL), addr_list);
ASSERT_EQ(NULL, addr_list[1]);
ASSERT_EQ(inet_addr("8.8.8.8"), *addr_list[0]);
+ // Check that h_addr also matches as in some libc's it may be a separate
+ // member.
+ in_addr_t* first_addr = reinterpret_cast<in_addr_t*>(host->h_addr);
+ ASSERT_EQ(inet_addr("8.8.8.8"), *first_addr);
}
// These utility functions are only used for newlib (glibc provides its own