diff options
author | dkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-05 19:38:54 +0000 |
---|---|---|
committer | dkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-05 19:38:54 +0000 |
commit | 212d14930e66db247e71f72cd91c480c1f7c9374 (patch) | |
tree | a0edae4ab0f2adcb76f22c3a64a1e6f75f56e902 /net/base | |
parent | 29d1eb815f296355e63a555729abc17b896d220a (diff) | |
download | chromium_src-212d14930e66db247e71f72cd91c480c1f7c9374.zip chromium_src-212d14930e66db247e71f72cd91c480c1f7c9374.tar.gz chromium_src-212d14930e66db247e71f72cd91c480c1f7c9374.tar.bz2 |
Modify HostResolver slightly to build on posix as well as windows.
Review URL: http://codereview.chromium.org/403
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/host_resolver.cc | 10 | ||||
-rw-r--r-- | net/base/host_resolver_unittest.cc | 41 |
2 files changed, 51 insertions, 0 deletions
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 |