diff options
-rw-r--r-- | net/SConscript | 3 | ||||
-rw-r--r-- | net/base/host_resolver.cc | 10 | ||||
-rw-r--r-- | net/base/host_resolver_unittest.cc | 41 | ||||
-rw-r--r-- | net/build/net_unittests.vcproj | 4 |
4 files changed, 57 insertions, 1 deletions
diff --git a/net/SConscript b/net/SConscript index 650bd85..519d5ea 100644 --- a/net/SConscript +++ b/net/SConscript @@ -41,6 +41,7 @@ input_files = [ 'base/filter.cc', 'base/gzip_filter.cc', 'base/gzip_header.cc', + 'base/host_resolver.cc', 'base/mime_sniffer.cc', 'base/net_errors.cc', 'base/net_module.cc', @@ -82,7 +83,6 @@ if env['PLATFORM'] == 'win32': 'base/client_socket_factory.cc', 'base/directory_lister.cc', 'base/dns_resolution_observer.cc', - 'base/host_resolver.cc', 'base/listen_socket.cc', 'base/mime_util.cc', 'base/ssl_client_socket.cc', @@ -212,6 +212,7 @@ unittest_files = [ 'base/data_url_unittest.cc', 'base/escape_unittest.cc', 'base/gzip_filter_unittest.cc', + 'base/host_resolver_unittest.cc', 'base/mime_sniffer_unittest.cc', 'base/net_util_unittest.cc', 'base/registry_controlled_domain_unittest.cc', diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc index 5e9f317..b6d8498 100644 --- a/net/base/host_resolver.cc +++ b/net/base/host_resolver.cc @@ -4,15 +4,23 @@ #include "net/base/host_resolver.h" +#if defined(OS_WIN) #include <ws2tcpip.h> #include <wspiapi.h> // Needed for Win2k compat. +#elif defined(OS_POSIX) +#include <netdb.h> +#include <sys/socket.h> +#endif #include "base/message_loop.h" #include "base/string_util.h" #include "base/worker_pool.h" #include "net/base/address_list.h" #include "net/base/net_errors.h" + +#if defined(OS_WIN) #include "net/base/winsock_init.h" +#endif namespace net { @@ -126,7 +134,9 @@ class HostResolver::Request : //----------------------------------------------------------------------------- HostResolver::HostResolver() { +#if defined(OS_WIN) EnsureWinsockInit(); +#endif } HostResolver::~HostResolver() { diff --git a/net/base/host_resolver_unittest.cc b/net/base/host_resolver_unittest.cc new file mode 100644 index 0000000..447d5c7 --- /dev/null +++ b/net/base/host_resolver_unittest.cc @@ -0,0 +1,41 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/host_resolver.h" +#include "net/base/address_list.h" +#include "testing/gtest/include/gtest/gtest.h" + +#ifdef OS_WIN +#include <ws2tcpip.h> +#include <wspiapi.h> +#endif +#ifdef OS_POSIX +#include <netdb.h> +#endif + +namespace { + +class HostResolverTest : public testing::Test { +}; + +TEST(HostResolverTest, NumericAddresses) { + // Stevens says dotted quads with AI_UNSPEC resolve to a single sockaddr_in. + + net::HostResolver host_resolver; + net::AddressList adrlist; + const int kPortnum = 5555; + int err = host_resolver.Resolve("127.0.0.1", kPortnum, &adrlist, NULL); + EXPECT_EQ(0, err); + + const struct addrinfo* ainfo = adrlist.head(); + EXPECT_EQ(NULL, ainfo->ai_next); + EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); + + const struct sockaddr* sa = ainfo->ai_addr; + const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; + EXPECT_EQ(htons(kPortnum), sa_in->sin_port); + EXPECT_EQ(htonl(0x7f000001), sa_in->sin_addr.s_addr); +} + +} // namespace diff --git a/net/build/net_unittests.vcproj b/net/build/net_unittests.vcproj index d1d720d..d2a0a90 100644 --- a/net/build/net_unittests.vcproj +++ b/net/build/net_unittests.vcproj @@ -315,6 +315,10 @@ > </File> <File + RelativePath="..\base\host_resolver_unittest.cc" + > + </File> + <File RelativePath="..\base\listen_socket_unittest.cc" > </File> |