diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 03:14:42 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 03:14:42 +0000 |
commit | d1388f48fc5971d3bddeca6dd6c0c44f63552063 (patch) | |
tree | 8677600788ea2ae558e2cf7c2a18b11b085e9061 /net/base/net_util_unittest.cc | |
parent | 0738a30690b8992c412ac968816e1ea8479577d8 (diff) | |
download | chromium_src-d1388f48fc5971d3bddeca6dd6c0c44f63552063.zip chromium_src-d1388f48fc5971d3bddeca6dd6c0c44f63552063.tar.gz chromium_src-d1388f48fc5971d3bddeca6dd6c0c44f63552063.tar.bz2 |
In addition to the logging the IP address that a TCP connect is made to, also include the port number.
This helps when debugging situations where the port has been changed.
Review URL: http://codereview.chromium.org/2808008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util_unittest.cc')
-rw-r--r-- | net/base/net_util_unittest.cc | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index 9bc5d58..4e760fe 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -373,7 +373,7 @@ struct UrlTestData { // Returns an addrinfo for the given 32-bit address (IPv4.) // The result lives in static storage, so don't delete it. // |bytes| should be an array of length 4. -const struct addrinfo* GetIPv4Address(const uint8* bytes) { +const struct addrinfo* GetIPv4Address(const uint8* bytes, int port) { static struct addrinfo static_ai; static struct sockaddr_in static_addr4; @@ -386,7 +386,7 @@ const struct addrinfo* GetIPv4Address(const uint8* bytes) { struct sockaddr_in* addr4 = &static_addr4; memset(addr4, 0, sizeof(static_addr4)); - addr4->sin_port = htons(80); + addr4->sin_port = htons(port); addr4->sin_family = ai->ai_family; memcpy(&addr4->sin_addr, bytes, 4); @@ -397,7 +397,7 @@ const struct addrinfo* GetIPv4Address(const uint8* bytes) { // Returns a addrinfo for the given 128-bit address (IPv6.) // The result lives in static storage, so don't delete it. // |bytes| should be an array of length 16. -const struct addrinfo* GetIPv6Address(const uint8* bytes) { +const struct addrinfo* GetIPv6Address(const uint8* bytes, int port) { static struct addrinfo static_ai; static struct sockaddr_in6 static_addr6; @@ -410,7 +410,7 @@ const struct addrinfo* GetIPv6Address(const uint8* bytes) { struct sockaddr_in6* addr6 = &static_addr6; memset(addr6, 0, sizeof(static_addr6)); - addr6->sin6_port = htons(80); + addr6->sin6_port = htons(port); addr6->sin6_family = ai->ai_family; memcpy(&addr6->sin6_addr, bytes, 16); @@ -418,7 +418,6 @@ const struct addrinfo* GetIPv6Address(const uint8* bytes) { return ai; } - // A helper for IDN*{Fast,Slow}. // Append "::<language list>" to |expected| and |actual| to make it // easy to tell which sub-case fails without debugging. @@ -1260,7 +1259,7 @@ TEST(NetUtilTest, NetAddressToString_IPv4) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - const addrinfo* ai = GetIPv4Address(tests[i].addr); + const addrinfo* ai = GetIPv4Address(tests[i].addr, 80); std::string result = net::NetAddressToString(ai); EXPECT_EQ(std::string(tests[i].result), result); } @@ -1277,7 +1276,7 @@ TEST(NetUtilTest, NetAddressToString_IPv6) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - const addrinfo* ai = GetIPv6Address(tests[i].addr); + const addrinfo* ai = GetIPv6Address(tests[i].addr, 80); std::string result = net::NetAddressToString(ai); // Allow NetAddressToString() to fail, in case the system doesn't // support IPv6. @@ -1286,6 +1285,26 @@ TEST(NetUtilTest, NetAddressToString_IPv6) { } } +TEST(NetUtilTest, NetAddressToStringWithPort_IPv4) { + uint8 addr[] = {127, 0, 0, 1}; + const addrinfo* ai = GetIPv4Address(addr, 166); + std::string result = net::NetAddressToStringWithPort(ai); + EXPECT_EQ("127.0.0.1:166", result); +} + +TEST(NetUtilTest, NetAddressToStringWithPort_IPv6) { + uint8 addr[] = { + 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA, + 0x98, 0x76, 0x54, 0x32, 0x10 + }; + const addrinfo* ai = GetIPv6Address(addr, 361); + std::string result = net::NetAddressToStringWithPort(ai); + + // May fail on systems that don't support IPv6. + if (!result.empty()) + EXPECT_EQ("[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:361", result); +} + TEST(NetUtilTest, GetHostName) { // We can't check the result of GetHostName() directly, since the result // will differ across machines. Our goal here is to simply exercise the |