IPv6 scope IDs are unsigned

We need to make sure that a large scope ID saved in a QString does get
converted properly back to an integer.

Change-Id: Iee8cbc07c4434ce9b560ffff13c9bd0e9008bd9c
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Thiago Macieira 2015-03-08 22:23:47 -07:00
parent bc59424ed4
commit f5edf2b6fb
3 changed files with 3 additions and 3 deletions

View File

@ -100,7 +100,7 @@ static QHostAddress addressFromSockaddr(sockaddr *sa, int ifindex = 0, const QSt
address.setScopeId(QLatin1String(scopeid));
} else
#endif
address.setScopeId(QString::number(scope));
address.setScopeId(QString::number(uint(scope)));
}
}
return address;

View File

@ -134,7 +134,7 @@ static inline uint makeScopeId(const QHostAddress &addr)
return 0;
bool ok;
uint id = scopeid.toInt(&ok);
uint id = scopeid.toUInt(&ok);
#ifndef QT_NO_IPV6IFNAME
if (!ok)
id = ::if_nametoindex(scopeid.toLatin1());

View File

@ -209,7 +209,7 @@ void QNativeSocketEnginePrivate::setPortAndAddress(sockaddr_in * sockAddrIPv4, q
|| socketProtocol == QAbstractSocket::AnyIPProtocol) {
memset(sockAddrIPv6, 0, sizeof(qt_sockaddr_in6));
sockAddrIPv6->sin6_family = AF_INET6;
sockAddrIPv6->sin6_scope_id = address.scopeId().toInt();
sockAddrIPv6->sin6_scope_id = address.scopeId().toUInt();
WSAHtons(socketDescriptor, port, &(sockAddrIPv6->sin6_port));
Q_IPV6ADDR tmp = address.toIPv6Address();
memcpy(&(sockAddrIPv6->sin6_addr.qt_s6_addr), &tmp, sizeof(tmp));