diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index db031fcc6b..5087e761eb 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -89,9 +89,19 @@ 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(((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)); + } + } return address; } diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp index d1d26598ac..1f4ac7ff7a 100644 --- a/src/network/kernel/qnetworkinterface_win.cpp +++ b/src/network/kernel/qnetworkinterface_win.cpp @@ -91,9 +91,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;