summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-07 06:40:06 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-07 06:40:06 +0000
commit68abc22003015ced6e49012be439c27b81232432 (patch)
treecb562dc98c5002656e7ed91f60373cd7312d8ba6 /net/base/net_util.cc
parent304356e13d4e4e081408ccaf417e67433b1b8ba7 (diff)
downloadchromium_src-68abc22003015ced6e49012be439c27b81232432.zip
chromium_src-68abc22003015ced6e49012be439c27b81232432.tar.gz
chromium_src-68abc22003015ced6e49012be439c27b81232432.tar.bz2
Add IPv6 probing support, and disable IPv6 resolution when it is useless
I've added minimal probing to check if IPv6 is at all possible, and when it is not, then we disable IPv6 resolution. I've also added histograms and A/B test support to evaluate the impact of this change. r=wtc,eroman Review URL: http://codereview.chromium.org/579010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 43fa906..01567bc 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1538,4 +1538,49 @@ void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports) {
explicitly_allowed_ports = ports;
}
+enum IPv6SupportStatus {
+ kIPv6CannotCreateSockets,
+ kIPv6CanCreateSockets,
+ kIPv6SupportMax // Bounding values for enumeration.
+};
+
+static void IPv6SupportResults(IPv6SupportStatus result) {
+ UMA_HISTOGRAM_ENUMERATION("Net.IPv6Status", result, kIPv6SupportMax);
+}
+
+// TODO(jar): The following is a simple estimate of IPv6 support. We may need
+// to do a test resolution, and a test connection, to REALLY verify support.
+// static
+#if defined(OS_POSIX)
+bool IPv6Supported() {
+ int test_socket;
+
+ test_socket = socket(AF_INET6, SOCK_STREAM, 0);
+ if (test_socket == -1) {
+ IPv6SupportResults(kIPv6CannotCreateSockets);
+ return false;
+ }
+
+ close(test_socket);
+ IPv6SupportResults(kIPv6CanCreateSockets);
+ return true;
+}
+#else // defined(OS_POSIX)
+bool IPv6Supported() {
+ EnsureWinsockInit();
+ SOCKET test_socket;
+
+ test_socket = socket(AF_INET6, SOCK_STREAM, 0);
+ if (test_socket == INVALID_SOCKET) {
+ IPv6SupportResults(kIPv6CannotCreateSockets);
+ return false;
+ }
+
+ closesocket(test_socket);
+ IPv6SupportResults(kIPv6CanCreateSockets);
+ return true;
+}
+#endif // defined(OS_POSIX)
+
+
} // namespace net