net: stop publishing GetPortFromSockaddr() to the world

And for that matter GetPortFieldFromSockaddr(). Move them into the
unnamed namespace in ip_endpoint_unittest.cc since it is used only by a
single test there.

BUG=488531
TEST=net_unittests --gtest_filter=IPEndPoint*
[email protected]

Review URL: https://codereview.chromium.org/1547473004

Cr-Commit-Position: refs/heads/master@{#366691}
diff --git a/net/base/ip_endpoint_unittest.cc b/net/base/ip_endpoint_unittest.cc
index 5266ea66..4da0bbe 100644
--- a/net/base/ip_endpoint_unittest.cc
+++ b/net/base/ip_endpoint_unittest.cc
@@ -4,20 +4,52 @@
 
 #include "net/base/ip_endpoint.h"
 
-#include "base/strings/string_number_conversions.h"
-#include "net/base/net_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
+#include "build/build_config.h"
+
 #if defined(OS_WIN)
 #include <winsock2.h>
 #elif defined(OS_POSIX)
 #include <netinet/in.h>
 #endif
 
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/sys_byteorder.h"
+#include "net/base/net_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
 namespace net {
 
 namespace {
 
+// Retuns the port field of the |sockaddr|.
+const uint16_t* GetPortFieldFromSockaddr(const struct sockaddr* address,
+                                         socklen_t address_len) {
+  if (address->sa_family == AF_INET) {
+    DCHECK_LE(sizeof(sockaddr_in), static_cast<size_t>(address_len));
+    const struct sockaddr_in* sockaddr =
+        reinterpret_cast<const struct sockaddr_in*>(address);
+    return &sockaddr->sin_port;
+  } else if (address->sa_family == AF_INET6) {
+    DCHECK_LE(sizeof(sockaddr_in6), static_cast<size_t>(address_len));
+    const struct sockaddr_in6* sockaddr =
+        reinterpret_cast<const struct sockaddr_in6*>(address);
+    return &sockaddr->sin6_port;
+  } else {
+    NOTREACHED();
+    return NULL;
+  }
+}
+
+// Returns the value of port in |sockaddr| (in host byte ordering).
+int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
+  const uint16_t* port_field = GetPortFieldFromSockaddr(address, address_len);
+  if (!port_field)
+    return -1;
+  return base::NetToHost16(*port_field);
+}
+
 struct TestData {
   std::string host;
   std::string host_normalized;
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 8ce1a8a2..e4258ae 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -406,31 +406,6 @@
   return url.ReplaceComponents(replacements);
 }
 
-const uint16_t* GetPortFieldFromSockaddr(const struct sockaddr* address,
-                                         socklen_t address_len) {
-  if (address->sa_family == AF_INET) {
-    DCHECK_LE(sizeof(sockaddr_in), static_cast<size_t>(address_len));
-    const struct sockaddr_in* sockaddr =
-        reinterpret_cast<const struct sockaddr_in*>(address);
-    return &sockaddr->sin_port;
-  } else if (address->sa_family == AF_INET6) {
-    DCHECK_LE(sizeof(sockaddr_in6), static_cast<size_t>(address_len));
-    const struct sockaddr_in6* sockaddr =
-        reinterpret_cast<const struct sockaddr_in6*>(address);
-    return &sockaddr->sin6_port;
-  } else {
-    NOTREACHED();
-    return NULL;
-  }
-}
-
-int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
-  const uint16_t* port_field = GetPortFieldFromSockaddr(address, address_len);
-  if (!port_field)
-    return -1;
-  return base::NetToHost16(*port_field);
-}
-
 bool ResolveLocalHostname(base::StringPiece host,
                           uint16_t port,
                           AddressList* address_list) {
diff --git a/net/base/net_util.h b/net/base/net_util.h
index 9c61fcfa1..1d3d158 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -162,13 +162,6 @@
 //   - reference section
 NET_EXPORT GURL SimplifyUrlForRequest(const GURL& url);
 
-// Retuns the port field of the |sockaddr|.
-const uint16_t* GetPortFieldFromSockaddr(const struct sockaddr* address,
-                                         socklen_t address_len);
-// Returns the value of port in |sockaddr| (in host byte ordering).
-NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address,
-                                           socklen_t address_len);
-
 // Resolves a local hostname (such as "localhost" or "localhost6") into
 // IP endpoints with the given port. Returns true if |host| is a local
 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6")