summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-10-04 12:00:57 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-11-04 19:12:18 +0000
commit484a186f50de59279cf3c02088273ff114f4cfcf (patch)
tree20fb181769b34199858e214b7faa38345b816b66 /src/network/socket
parentd674d227f7ab22aed206d3a7f5c96e5e8dfa48f2 (diff)
QNativeSocketEngine/Win: fix getting the datagram destination
Looks like I never even tested this. There were two problems: 1) when we asked for the recvmsg and sendmsg functions, we used the wrong variable (socketDescriptor was still -1) 2) we extracted the destination addresses, but never set them in the QIpPacketHeader object The added tests confirm that this works on Windows, Linux, Darwin, FreeBSD. There also seems to be a problem, obtaining the destination address on an IPv4 socket with a dual-stack sender (I can reproduce that on FreeBSD, macOS and Windows, plus an old version of Linux). Task-number: QTBUG-63605 Change-Id: I638cf58bfa7b4e5fb386fffd14ea732bddbc0c42 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index eb633eb1d2..3ecfb06411 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -408,13 +408,13 @@ bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType soc
// get the pointer to sendmsg and recvmsg
DWORD bytesReturned;
GUID recvmsgguid = WSAID_WSARECVMSG;
- if (WSAIoctl(socketDescriptor, SIO_GET_EXTENSION_FUNCTION_POINTER,
+ if (WSAIoctl(socket, SIO_GET_EXTENSION_FUNCTION_POINTER,
&recvmsgguid, sizeof(recvmsgguid),
&recvmsg, sizeof(recvmsg), &bytesReturned, NULL, NULL) == SOCKET_ERROR)
recvmsg = 0;
GUID sendmsgguid = WSAID_WSASENDMSG;
- if (WSAIoctl(socketDescriptor, SIO_GET_EXTENSION_FUNCTION_POINTER,
+ if (WSAIoctl(socket, SIO_GET_EXTENSION_FUNCTION_POINTER,
&sendmsgguid, sizeof(sendmsgguid),
&sendmsg, sizeof(sendmsg), &bytesReturned, NULL, NULL) == SOCKET_ERROR)
sendmsg = 0;
@@ -1257,26 +1257,28 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxL
qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress);
}
- if (ret != -1 && recvmsg) {
+ if (ret != -1 && recvmsg && options != QAbstractSocketEngine::WantNone) {
// get the ancillary data
+ header->destinationPort = localPort;
WSACMSGHDR *cmsgptr;
for (cmsgptr = WSA_CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
cmsgptr = WSA_CMSG_NXTHDR(&msg, cmsgptr)) {
if (cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_PKTINFO
&& cmsgptr->cmsg_len >= WSA_CMSG_LEN(sizeof(in6_pktinfo))) {
in6_pktinfo *info = reinterpret_cast<in6_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
- QHostAddress target(reinterpret_cast<quint8 *>(&info->ipi6_addr));
- if (info->ipi6_ifindex)
- target.setScopeId(QString::number(info->ipi6_ifindex));
+
+ header->destinationAddress.setAddress(reinterpret_cast<quint8 *>(&info->ipi6_addr));
+ header->ifindex = info->ipi6_ifindex;
+ if (header->ifindex)
+ header->destinationAddress.setScopeId(QString::number(info->ipi6_ifindex));
}
if (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_PKTINFO
&& cmsgptr->cmsg_len >= WSA_CMSG_LEN(sizeof(in_pktinfo))) {
in_pktinfo *info = reinterpret_cast<in_pktinfo *>(WSA_CMSG_DATA(cmsgptr));
u_long addr;
WSANtohl(socketDescriptor, info->ipi_addr.s_addr, &addr);
- QHostAddress target(addr);
- if (info->ipi_ifindex)
- target.setScopeId(QString::number(info->ipi_ifindex));
+ header->destinationAddress.setAddress(addr);
+ header->ifindex = info->ipi_ifindex;
}
if (cmsgptr->cmsg_len == WSA_CMSG_LEN(sizeof(int))