diff options
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/kernel.pri | 4 | ||||
-rw-r--r-- | src/network/kernel/qdnslookup_unix.cpp | 2 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface.cpp | 46 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface.h | 2 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface_p.h | 3 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface_unix.cpp | 62 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface_win.cpp | 43 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface_winrt.cpp | 13 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy.cpp | 10 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_blackberry.cpp | 165 |
10 files changed, 162 insertions, 188 deletions
diff --git a/src/network/kernel/kernel.pri b/src/network/kernel/kernel.pri index ddb30b7b6f..120a9650ac 100644 --- a/src/network/kernel/kernel.pri +++ b/src/network/kernel/kernel.pri @@ -55,10 +55,6 @@ mac { mac:!ios:SOURCES += kernel/qnetworkproxy_mac.cpp else:win32:SOURCES += kernel/qnetworkproxy_win.cpp -else:blackberry { - SOURCES += kernel/qnetworkproxy_blackberry.cpp - LIBS_PRIVATE += -lbps -} else:contains(QT_CONFIG, libproxy) { SOURCES += kernel/qnetworkproxy_libproxy.cpp LIBS_PRIVATE += -lproxy diff --git a/src/network/kernel/qdnslookup_unix.cpp b/src/network/kernel/qdnslookup_unix.cpp index dc8ec5a300..b78db338ce 100644 --- a/src/network/kernel/qdnslookup_unix.cpp +++ b/src/network/kernel/qdnslookup_unix.cpp @@ -37,6 +37,7 @@ #include <qscopedpointer.h> #include <qurl.h> #include <private/qmutexpool_p.h> +#include <private/qnativesocketengine_p.h> #include <sys/types.h> #include <netinet/in.h> @@ -160,6 +161,7 @@ void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestN state._u._ext.nscount6 = 1; ns->sin6_family = AF_INET6; ns->sin6_port = htons(53); + SetSALen::set(ns, sizeof(*ns)); Q_IPV6ADDR ipv6Address = nameserver.toIPv6Address(); for (int i=0; i<16; i++) { diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp index 4a527052d1..81906edc47 100644 --- a/src/network/kernel/qnetworkinterface.cpp +++ b/src/network/kernel/qnetworkinterface.cpp @@ -519,6 +519,31 @@ QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const } /*! + \since 5.7 + + Returns the index of the interface whose name is \a name or 0 if there is + no interface with that name. This function should produce the same result + as the following code, but will probably execute faster. + + \code + QNetworkInterface::interfaceFromName(name).index() + \endcode + + \sa interfaceFromName(), interfaceNameFromIndex(), QUdpDatagram::interfaceIndex() +*/ +int QNetworkInterface::interfaceIndexFromName(const QString &name) +{ + if (name.isEmpty()) + return 0; + + bool ok; + uint id = name.toUInt(&ok); + if (!ok) + id = QNetworkInterfaceManager::interfaceIndexFromName(name); + return int(id); +} + +/*! Returns a QNetworkInterface object for the interface named \a name. If no such interface exists, this function returns an invalid QNetworkInterface object. @@ -553,6 +578,27 @@ QNetworkInterface QNetworkInterface::interfaceFromIndex(int index) } /*! + \since 5.7 + + Returns the name of the interface whose index is \a index or an empty + string if there is no interface with that index. This function should + produce the same result as the following code, but will probably execute + faster. + + \code + QNetworkInterface::interfaceFromIndex(index).name() + \endcode + + \sa interfaceFromIndex(), interfaceIndexFromName(), QUdpDatagram::interfaceIndex() +*/ +QString QNetworkInterface::interfaceNameFromIndex(int index) +{ + if (!index) + return QString(); + return QNetworkInterfaceManager::interfaceNameFromIndex(index); +} + +/*! Returns a listing of all the network interfaces found on the host machine. In case of failure it returns a list with zero elements. */ diff --git a/src/network/kernel/qnetworkinterface.h b/src/network/kernel/qnetworkinterface.h index b3daa3d4a0..bd57aea1cb 100644 --- a/src/network/kernel/qnetworkinterface.h +++ b/src/network/kernel/qnetworkinterface.h @@ -113,8 +113,10 @@ public: QString hardwareAddress() const; QList<QNetworkAddressEntry> addressEntries() const; + static int interfaceIndexFromName(const QString &name); static QNetworkInterface interfaceFromName(const QString &name); static QNetworkInterface interfaceFromIndex(int index); + static QString interfaceNameFromIndex(int index); static QList<QNetworkInterface> allInterfaces(); static QList<QHostAddress> allAddresses(); diff --git a/src/network/kernel/qnetworkinterface_p.h b/src/network/kernel/qnetworkinterface_p.h index 140a28c536..146ba7820c 100644 --- a/src/network/kernel/qnetworkinterface_p.h +++ b/src/network/kernel/qnetworkinterface_p.h @@ -100,6 +100,9 @@ public: QSharedDataPointer<QNetworkInterfacePrivate> interfaceFromIndex(int index); QList<QSharedDataPointer<QNetworkInterfacePrivate> > allInterfaces(); + static uint interfaceIndexFromName(const QString &name); + static QString interfaceNameFromIndex(uint index); + // convenience: QSharedDataPointer<QNetworkInterfacePrivate> empty; diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index 5e6d24dd44..e7b62effcb 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtNetwork module of the Qt Toolkit. @@ -93,14 +94,8 @@ static QHostAddress addressFromSockaddr(sockaddr *sa, int ifindex = 0, const QSt // this is the most likely scenario: // a scope ID in a socket is that of the interface this address came from address.setScopeId(ifname); - } else if (scope) { -#ifndef QT_NO_IPV6IFNAME - char scopeid[IFNAMSIZ]; - if (::if_indextoname(scope, scopeid)) { - address.setScopeId(QLatin1String(scopeid)); - } else -#endif - address.setScopeId(QString::number(uint(scope))); + } else if (scope) { + address.setScopeId(QNetworkInterfaceManager::interfaceNameFromIndex(scope)); } } return address; @@ -124,6 +119,53 @@ static QNetworkInterface::InterfaceFlags convertFlags(uint rawFlags) return flags; } +uint QNetworkInterfaceManager::interfaceIndexFromName(const QString &name) +{ +#ifndef QT_NO_IPV6IFNAME + return ::if_nametoindex(name.toLatin1()); +#elif defined(SIOCGIFINDEX) + struct ifreq req; + int socket = qt_safe_socket(AF_INET, SOCK_STREAM, 0); + if (socket < 0) + return 0; + + QByteArray name8bit = name.toLatin1(); + memset(&req, 0, sizeof(ifreq)); + memcpy(req.ifr_name, name8bit, qMin<int>(name8bit.length() + 1, sizeof(req.ifr_name) - 1)); + + uint id = 0; + if (qt_safe_ioctl(socket, SIOCGIFINDEX, &req) >= 0) + id = req.ifr_ifindex; + qt_safe_close(socket); + return id; +#else + return 0; +#endif +} + +QString QNetworkInterfaceManager::interfaceNameFromIndex(uint index) +{ +#ifndef QT_NO_IPV6IFNAME + char buf[IF_NAMESIZE]; + if (::if_indextoname(index, buf)) + return QString::fromLatin1(buf); +#elif defined(SIOCGIFNAME) + struct ifreq req; + int socket = qt_safe_socket(AF_INET, SOCK_STREAM, 0); + if (socket >= 0) { + memset(&req, 0, sizeof(ifreq)); + req.ifr_ifindex = index; + + if (qt_safe_ioctl(socket, SIOCGIFNAME, &req) >= 0) { + qt_safe_close(socket); + return QString::fromLatin1(req.ifr_name); + } + qt_safe_close(socket); + } +#endif + return QString::number(uint(index)); +} + #ifdef QT_NO_GETIFADDRS // getifaddrs not available @@ -189,7 +231,11 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList<QNetworkInterfa // Get the interface index # ifdef SIOCGIFINDEX if (qt_safe_ioctl(socket, SIOCGIFINDEX, &req) >= 0) +# if defined(Q_OS_HAIKU) + ifindex = req.ifr_index; +# else ifindex = req.ifr_ifindex; +# endif # else ifindex = if_nametoindex(req.ifr_name); # endif diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp index 907638f73e..238f913846 100644 --- a/src/network/kernel/qnetworkinterface_win.cpp +++ b/src/network/kernel/qnetworkinterface_win.cpp @@ -57,8 +57,14 @@ QT_BEGIN_NAMESPACE +typedef NETIO_STATUS (WINAPI *PtrConvertInterfaceIndexToLuid)(NET_IFINDEX, PNET_LUID); typedef NETIO_STATUS (WINAPI *PtrConvertInterfaceLuidToName)(const NET_LUID *, PWSTR, SIZE_T); +typedef NETIO_STATUS (WINAPI *PtrConvertInterfaceLuidToIndex)(const NET_LUID *, PNET_IFINDEX); +typedef NETIO_STATUS (WINAPI *PtrConvertInterfaceNameToLuid)(const WCHAR *, PNET_LUID); +static PtrConvertInterfaceIndexToLuid ptrConvertInterfaceIndexToLuid = 0; static PtrConvertInterfaceLuidToName ptrConvertInterfaceLuidToName = 0; +static PtrConvertInterfaceLuidToIndex ptrConvertInterfaceLuidToIndex = 0; +static PtrConvertInterfaceNameToLuid ptrConvertInterfaceNameToLuid = 0; static void resolveLibs() { @@ -71,10 +77,16 @@ static void resolveLibs() #if defined(Q_OS_WINCE) // since Windows Embedded Compact 7 + ptrConvertInterfaceIndexToLuid = (PtrConvertInterfaceIndexToLuid)GetProcAddress(iphlpapiHnd, L"ConvertInterfaceIndexToLuid"); ptrConvertInterfaceLuidToName = (PtrConvertInterfaceLuidToName)GetProcAddress(iphlpapiHnd, L"ConvertInterfaceLuidToNameW"); + ptrConvertInterfaceLuidToIndex = (PtrConvertInterfaceLuidToIndex)GetProcAddress(iphlpapiHnd, L"ConvertInterfaceLuidToIndex"); + ptrConvertInterfaceNameToLuid = (PtrConvertInterfaceNameToLuid)GetProcAddress(iphlpapiHnd, L"ConvertInterfaceNameToLuidW"); #else // since Windows Vista + ptrConvertInterfaceIndexToLuid = (PtrConvertInterfaceIndexToLuid)GetProcAddress(iphlpapiHnd, "ConvertInterfaceIndexToLuid"); ptrConvertInterfaceLuidToName = (PtrConvertInterfaceLuidToName)GetProcAddress(iphlpapiHnd, "ConvertInterfaceLuidToNameW"); + ptrConvertInterfaceLuidToIndex = (PtrConvertInterfaceLuidToIndex)GetProcAddress(iphlpapiHnd, "ConvertInterfaceLuidToIndex"); + ptrConvertInterfaceNameToLuid = (PtrConvertInterfaceNameToLuid)GetProcAddress(iphlpapiHnd, "ConvertInterfaceNameToLuidW"); #endif done = true; } @@ -92,13 +104,42 @@ static QHostAddress addressFromSockaddr(sockaddr *sa) address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr); int scope = ((sockaddr_in6 *)sa)->sin6_scope_id; if (scope) - address.setScopeId(QString::number(scope)); + address.setScopeId(QNetworkInterfaceManager::interfaceNameFromIndex(scope)); } else qWarning("Got unknown socket family %d", sa->sa_family); return address; } +uint QNetworkInterfaceManager::interfaceIndexFromName(const QString &name) +{ + resolveLibs(); + if (!ptrConvertInterfaceNameToLuid || !ptrConvertInterfaceLuidToIndex) + return 0; + + NET_IFINDEX id; + NET_LUID luid; + if (ptrConvertInterfaceNameToLuid(reinterpret_cast<const wchar_t *>(name.constData()), &luid) == NO_ERROR + && ptrConvertInterfaceLuidToIndex(&luid, &id) == NO_ERROR) + return uint(id); + return 0; +} + +QString QNetworkInterfaceManager::interfaceNameFromIndex(uint index) +{ + resolveLibs(); + if (ptrConvertInterfaceIndexToLuid && ptrConvertInterfaceLuidToName) { + NET_LUID luid; + if (ptrConvertInterfaceIndexToLuid(index, &luid) == NO_ERROR) { + WCHAR buf[IF_MAX_STRING_SIZE + 1]; + if (ptrConvertInterfaceLuidToName(&luid, buf, sizeof(buf)/sizeof(buf[0])) == NO_ERROR) + return QString::fromWCharArray(buf); + } + } + + return QString::number(index); +} + static QHash<QHostAddress, QHostAddress> ipv4Netmasks() { //Retrieve all the IPV4 addresses & netmasks diff --git a/src/network/kernel/qnetworkinterface_winrt.cpp b/src/network/kernel/qnetworkinterface_winrt.cpp index 1945b2427f..1e22ab15da 100644 --- a/src/network/kernel/qnetworkinterface_winrt.cpp +++ b/src/network/kernel/qnetworkinterface_winrt.cpp @@ -61,6 +61,19 @@ struct HostNameInfo { QString address; }; +uint QNetworkInterfaceManager::interfaceIndexFromName(const QString &name) +{ + // TBD - may not be possible + Q_UNUSED(name); + return 0; +} + +QString QNetworkInterfaceManager::interfaceNameFromIndex(uint index) +{ + // TBD - may not be possible + return QString::number(index); +} + static QNetworkInterfacePrivate *interfaceFromProfile(IConnectionProfile *profile, QList<HostNameInfo> *hostList) { if (!profile) diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp index 4c7c0c5442..4263938fdf 100644 --- a/src/network/kernel/qnetworkproxy.cpp +++ b/src/network/kernel/qnetworkproxy.cpp @@ -1530,12 +1530,6 @@ void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *fact SOCKS server for all queries. If SOCKS isn't enabled, it will use the HTTPS proxy for all TcpSocket and UrlRequest queries. - On BlackBerry, this function obtains proxy settings for the default - configuration using system configuration. The type will be set based on - protocol tag "http", "https", "ftp", respectively. By default, it - assumes http type. Proxy username and password are also set during - the query using system configuration. - On other systems, this function will pick up proxy settings from the "http_proxy" environment variable. This variable must be a URL using one of the following schemes: "http", "socks5" or "socks5h". @@ -1552,10 +1546,6 @@ void QNetworkProxyFactory::setApplicationProxyFactory(QNetworkProxyFactory *fact \li On Windows platforms, this function may take several seconds to execute depending on the configuration of the user's system. - - \li On BlackBerry, only UrlRequest and TcpSocket queries are supported. SOCKS is - not supported. The proxy credentials are only retrieved for the - default configuration. \endlist */ diff --git a/src/network/kernel/qnetworkproxy_blackberry.cpp b/src/network/kernel/qnetworkproxy_blackberry.cpp deleted file mode 100644 index ca30a65397..0000000000 --- a/src/network/kernel/qnetworkproxy_blackberry.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Research In Motion -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/** - * Some notes about the code: - * - * ** It is assumed that the system proxies are for url based requests - * ie. HTTP/HTTPS based. - */ - -#include <QtNetwork/qnetworkproxy.h> - -#ifndef QT_NO_NETWORKPROXY - - -#include <QtCore/qflags.h> -#include <QtCore/qurl.h> -#include <QtNetwork/qnetworkconfiguration.h> - -#include <bps/netstatus.h> -#include <errno.h> - - -QT_BEGIN_NAMESPACE - -QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) -{ - if (query.url().scheme() == QLatin1String("file") - || query.url().scheme() == QLatin1String("qrc")) - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - - if (query.queryType() != QNetworkProxyQuery::UrlRequest - && query.queryType() != QNetworkProxyQuery::TcpSocket) { - qWarning("Unsupported query type: %d", query.queryType()); - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - } - - QUrl url; - if (query.queryType() == QNetworkProxyQuery::UrlRequest) { - url = query.url(); - } else if (query.queryType() == QNetworkProxyQuery::TcpSocket - && !query.peerHostName().isEmpty()) { - url.setHost(query.peerHostName()); - switch (query.peerPort()) { - case 443: - url.setScheme(QStringLiteral("https")); - break; - case 21: - url.setScheme(QStringLiteral("ftp")); - break; - default: - // for unknown ports, we just pretend we are dealing - // with a HTTP URL, otherwise we will not get a proxy - // from the netstatus API - url.setScheme(QStringLiteral("http")); - } - } - - if (!url.isValid()) { - qWarning("Invalid URL: %s", qPrintable(url.toString())); - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - } - - netstatus_proxy_details_t details; - memset(&details, 0, sizeof(netstatus_proxy_details_t)); - -#if BPS_VERSION >= 3001001 - - QByteArray bUrl(url.toEncoded()); - QString sInterface(query.networkConfiguration().name()); - QByteArray bInterface; - if (!sInterface.isEmpty()) { - if (query.networkConfiguration().type() != QNetworkConfiguration::InternetAccessPoint) { - qWarning("Unsupported configuration type: %d", query.networkConfiguration().type()); - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - } - bInterface = sInterface.toUtf8(); - } - - if (netstatus_get_proxy_details_for_url(bUrl.constData(), (bInterface.isEmpty() ? NULL : bInterface.constData()), &details) != BPS_SUCCESS) { - qWarning("netstatus_get_proxy_details_for_url failed! errno: %d", errno); - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - } - -#else - - if (netstatus_get_proxy_details(&details) != BPS_SUCCESS) { - qWarning("netstatus_get_proxy_details failed! errno: %d", errno); - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - } - -#endif - - if (details.http_proxy_host == NULL) { // No proxy - netstatus_free_proxy_details(&details); - return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy); - } - - QNetworkProxy proxy; - - QString protocol = query.protocolTag(); - if (protocol.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { // http, https - proxy.setType((QNetworkProxy::HttpProxy)); - } else if (protocol == QLatin1String("ftp")) { - proxy.setType(QNetworkProxy::FtpCachingProxy); - } else { // assume http proxy - qDebug("Proxy type: %s assumed to be http proxy", qPrintable(protocol)); - proxy.setType((QNetworkProxy::HttpProxy)); - } - - // Set host - // Note: ftp and https proxy type fields *are* obsolete. - // The user interface allows only one host/port which gets duplicated - // to all proxy type fields. - proxy.setHostName(QString::fromUtf8(details.http_proxy_host)); - - // Set port - proxy.setPort(details.http_proxy_port); - - // Set username - if (details.http_proxy_login_user) - proxy.setUser(QString::fromUtf8(details.http_proxy_login_user)); - - // Set password - if (details.http_proxy_login_password) - proxy.setPassword(QString::fromUtf8(details.http_proxy_login_password)); - - netstatus_free_proxy_details(&details); - - return QList<QNetworkProxy>() << proxy; -} - -QT_END_NAMESPACE - -#endif |