summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 43fa906..a2eb04d 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1538,4 +1538,54 @@ void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports) {
explicitly_allowed_ports = ports;
}
+enum IPv6SupportStatus {
+ IPV6_CANNOT_CREATE_SOCKETS,
+ IPV6_CAN_CREATE_SOCKETS,
+ IPV6_SUPPORT_MAX // Bounding values for enumeration.
+};
+
+static void IPv6SupportResults(IPv6SupportStatus result) {
+ static bool run_once = false;
+ if (run_once)
+ return;
+ run_once = true;
+ UMA_HISTOGRAM_ENUMERATION("Net.IPv6Status", result, IPV6_SUPPORT_MAX);
+}
+
+// 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
+bool IPv6Supported() {
+#if defined(OS_POSIX)
+ int test_socket;
+
+ test_socket = socket(AF_INET6, SOCK_STREAM, 0);
+ if (test_socket == -1) {
+ IPv6SupportResults(IPV6_CANNOT_CREATE_SOCKETS);
+ return false;
+ }
+
+ close(test_socket);
+ IPv6SupportResults(IPV6_CAN_CREATE_SOCKETS);
+ return true;
+#elif defined(OS_WIN)
+ EnsureWinsockInit();
+ SOCKET test_socket;
+
+ test_socket = socket(AF_INET6, SOCK_STREAM, 0);
+ if (test_socket == INVALID_SOCKET) {
+ IPv6SupportResults(IPV6_CANNOT_CREATE_SOCKETS);
+ return false;
+ }
+
+ closesocket(test_socket);
+ IPv6SupportResults(IPV6_CAN_CREATE_SOCKETS);
+ return true;
+#else
+ NOTIMPLEMENTED();
+ return true;
+#endif // defined(various platforms)
+}
+
+
} // namespace net