summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2012-05-09 16:06:47 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-05-24 11:48:51 (GMT)
commit3c63d78cdf56f719b7d27a589389b5eda399f28a (patch)
treeafb4f7cec5397f38184f02198bbcf5eb3139156e /src/network
parent7be85320379f49f04da3860fa14c9929e329acdd (diff)
downloadQt-3c63d78cdf56f719b7d27a589389b5eda399f28a.zip
Qt-3c63d78cdf56f719b7d27a589389b5eda399f28a.tar.gz
Qt-3c63d78cdf56f719b7d27a589389b5eda399f28a.tar.bz2
Include scope ids in QHostAddress from QNetworkInterface
The scope ID is a required part of the address for link local addresses (to solve the problem of the same link local address being created by two machines on different networks). It is required to send packets to a link local address on Mac and Windows, although Linux multicasts if scope is missing. Task-number: QTBUG-25634 Change-Id: Ie2bb09df8d261eefcb81716bafeb1475f0bed5fe Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com> (cherry picked from commit b72c8dd8a248d67b1192e3baa1fca07244a3719d) Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/kernel/qnetworkinterface_unix.cpp13
-rw-r--r--src/network/kernel/qnetworkinterface_win.cpp7
2 files changed, 17 insertions, 3 deletions
diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp
index 8545e6e..1d2c577 100644
--- a/src/network/kernel/qnetworkinterface_unix.cpp
+++ b/src/network/kernel/qnetworkinterface_unix.cpp
@@ -81,8 +81,19 @@ static QHostAddress addressFromSockaddr(sockaddr *sa)
if (sa->sa_family == AF_INET)
address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr));
#ifndef QT_NO_IPV6
- else if (sa->sa_family == AF_INET6)
+ else if (sa->sa_family == AF_INET6) {
address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr);
+ int scope = ((sockaddr_in6 *)sa)->sin6_scope_id;
+ if (scope) {
+#ifndef QT_NO_IPV6IFNAME
+ char scopeid[IFNAMSIZ];
+ if (::if_indextoname(scope, scopeid)) {
+ address.setScopeId(QLatin1String(scopeid));
+ } else
+#endif
+ address.setScopeId(QString::number(scope));
+ }
+ }
#endif
return address;
diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp
index f2bb172..5224fd2 100644
--- a/src/network/kernel/qnetworkinterface_win.cpp
+++ b/src/network/kernel/qnetworkinterface_win.cpp
@@ -82,9 +82,12 @@ static QHostAddress addressFromSockaddr(sockaddr *sa)
if (sa->sa_family == AF_INET)
address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr));
- else if (sa->sa_family == AF_INET6)
+ else if (sa->sa_family == AF_INET6) {
address.setAddress(((qt_sockaddr_in6 *)sa)->sin6_addr.qt_s6_addr);
- else
+ int scope = ((qt_sockaddr_in6 *)sa)->sin6_scope_id;
+ if (scope)
+ address.setScopeId(QString::number(scope));
+ } else
qWarning("Got unknown socket family %d", sa->sa_family);
return address;