diff options
| author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2024-05-21 12:47:47 +0300 |
|---|---|---|
| committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2024-05-23 10:26:20 +0300 |
| commit | 4370f9f227fd60ae252fb040f660e7835316830f (patch) | |
| tree | 368f75a03d368dc9a83d8f003ae8c3adf3dcaa0d /src/network/kernel/qnetworkinterface_unix.cpp | |
| parent | 841bbbe8ec5eb9c822af4359278f73ae9a6599bb (diff) | |
Network: add MTU implementation when getifaddrs is defined
Task-number: QTBUG-125023
Change-Id: I288df0d766f23dc569cedba52523fadedbff6491
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/kernel/qnetworkinterface_unix.cpp')
| -rw-r--r-- | src/network/kernel/qnetworkinterface_unix.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index c0a7d9e00d0..39ff8dbb928 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -310,12 +310,20 @@ QT_BEGIN_INCLUDE_NAMESPACE QT_END_INCLUDE_NAMESPACE # endif +static int openSocket(int &socket) +{ + if (socket == -1) + socket = qt_safe_socket(AF_INET, SOCK_DGRAM, 0); + return socket; +} + # if defined(Q_OS_LINUX) && __GLIBC__ - 0 >= 2 && __GLIBC_MINOR__ - 0 >= 1 && !defined(QT_LINUXBASE) # include <netpacket/packet.h> static QList<QNetworkInterfacePrivate *> createInterfaces(ifaddrs *rawList) { Q_UNUSED(getMtu); + Q_UNUSED(openSocket); QList<QNetworkInterfacePrivate *> interfaces; QDuplicateTracker<QString> seenInterfaces; QDuplicateTracker<int> seenIndexes; @@ -387,13 +395,6 @@ QT_BEGIN_INCLUDE_NAMESPACE #endif // QT_PLATFORM_UIKIT QT_END_INCLUDE_NAMESPACE -static int openSocket(int &socket) -{ - if (socket == -1) - socket = qt_safe_socket(AF_INET, SOCK_DGRAM, 0); - return socket; -} - static QNetworkInterface::InterfaceType probeIfType(int socket, int iftype, struct ifmediareq *req) { // Determine the interface type. @@ -537,8 +538,8 @@ static void getAddressExtraInfo(QNetworkAddressEntry *entry, struct sockaddr *sa static QList<QNetworkInterfacePrivate *> createInterfaces(ifaddrs *rawList) { - Q_UNUSED(getMtu); QList<QNetworkInterfacePrivate *> interfaces; + int socket = -1; // make sure there's one entry for each interface for (ifaddrs *ptr = rawList; ptr; ptr = ptr->ifa_next) { @@ -559,9 +560,18 @@ static QList<QNetworkInterfacePrivate *> createInterfaces(ifaddrs *rawList) iface->index = ifindex; iface->name = QString::fromLatin1(ptr->ifa_name); iface->flags = convertFlags(ptr->ifa_flags); + + if ((socket = openSocket(socket)) >= 0) { + struct ifreq ifr; + qstrncpy(ifr.ifr_name, ptr->ifa_name, sizeof(ifr.ifr_name)); + iface->mtu = getMtu(socket, &ifr); + } } } + if (socket != -1) + qt_safe_close(socket); + return interfaces; } |
