From 411a4cb67cd3d976ddbd94b37a0ce936bfb223e5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 24 Mar 2018 08:26:11 +0800 Subject: [PATCH] QNetworkInterface/Linux: fix support for P-t-P tunnels The kernel stores the local address in IFA_LOCAL and the peer's address in IFA_ADDRESS. My testing with loopback, Ethernet, WiFi, OpenVPN TAP and TUN and Openconnect shows IFA_LOCAL is always passed and always correct, so we could have used just that, but let's leave the use of IFA_ADDRESS because that's also what all libcs' getifaddrs() do. [ChangeLog][QtNetwork][QNetworkInterface] Fixed a regression in reporting the local address of a point-to-point tunnel network interface. Task-number: QTBUG-67226 Change-Id: I04a43ee94975482f9e32fffd151eb393d1775580 Reviewed-by: Edward Welbourne --- src/network/kernel/qnetworkinterface_linux.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/network/kernel/qnetworkinterface_linux.cpp b/src/network/kernel/qnetworkinterface_linux.cpp index 01b28110707..5dc62bf7bbb 100644 --- a/src/network/kernel/qnetworkinterface_linux.cpp +++ b/src/network/kernel/qnetworkinterface_linux.cpp @@ -382,7 +382,14 @@ static void getAddresses(int sock, char *buf, QList auto payloadPtr = reinterpret_cast(RTA_DATA(rta)); switch (rta->rta_type) { - case IFA_ADDRESS: // address + case IFA_ADDRESS: + // Local address (all interfaces except for point-to-point) + if (entry.ip().isNull()) + entry.setIp(makeAddress(payloadPtr, payloadLen)); + break; + + case IFA_LOCAL: + // Override the local address (point-to-point interfaces) entry.setIp(makeAddress(payloadPtr, payloadLen)); break;