summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_unix.cpp
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2025-09-24 16:30:24 +0200
committerIvan Solovev <ivan.solovev@qt.io>2025-10-09 16:43:12 +0200
commite0c0b7cab2bbbec4ae6f5c9e55c949fd05ee4c64 (patch)
tree7800322eeee75a3347cdfcc3ffcbfec8d04f8c67 /src/network/socket/qnativesocketengine_unix.cpp
parent4ce110c50c7c2511626e79ad2d2270537c5ac279 (diff)
QNativeSocketEngine: enable dual-stack as early as possible
Try to disable the IPV6_V6ONLY socket option right after creating the socket. This is important, because it can affect how setting other options works. For example, on Windows we could not properly set the ReceivePacketInformation option before calling bind()/connectToHost(). If we're actually binding/connecting to an IPv6 address, then the pre-existing code in nativeBind()/nativeConnect() would take care of adjusting the option again. Task-number: QTBUG-80704 Task-number: QTBUG-139697 Pick-to: 6.10 6.8 Change-Id: I6d504d354f63f441c90df21f933fd800fafa655f Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket/qnativesocketengine_unix.cpp')
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index 0671854ccee..a9bc2d92b44 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -236,6 +236,20 @@ bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType soc
return false;
}
+ // Attempt to enable dual-stack
+ if (domain == AF_INET6) {
+ const int ipv6only = 0;
+ [[maybe_unused]] const int ret = ::setsockopt(socket, IPPROTO_IPV6, IPV6_V6ONLY,
+ &ipv6only, sizeof(ipv6only));
+#if defined (QNATIVESOCKETENGINE_DEBUG)
+ if (ret != 0) {
+ qDebug("QNativeSocketEnginePrivate::createNewSocket(%d, %d): "
+ "failed to set IPV6_V6ONLY to %d.",
+ socketType, socketProtocol, ipv6only);
+ }
+#endif
+ }
+
#if defined (QNATIVESOCKETENGINE_DEBUG)
qDebug("QNativeSocketEnginePrivate::createNewSocket(%d, %d) == true",
socketType, socketProtocol);