Remove vestiges of Qt's own sockaddr_in6 and sockaddr_storage
We weren't using qt_sockaddr_storage, so it's not a problem. But since we're not using it anyway, we don't really need it. The storage is only needed if we needed to get a bigger socket address and that only happens with Unix sockets (paths). sockaddr_in6, however, was just wrong. Some systems derived from BSD, like OS X, have a sXX_len field containing the length of the socket address structure and our qt_sockaddr_in6 was missing sin6_len. As a result, setting sin6_family was just plain wrong on little-endian systems. Like all modern systems running BSDs and OS X... Change-Id: I7de033f80b0e4431b7f1ffff13f900f004c55443 Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
452924c6ff
commit
b626a5859a
@ -136,7 +136,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
||||
// Reverse lookup
|
||||
if (local_getnameinfo) {
|
||||
sockaddr_in sa4;
|
||||
qt_sockaddr_in6 sa6;
|
||||
sockaddr_in6 sa6;
|
||||
sockaddr *sa;
|
||||
QT_SOCKLEN_T saSize;
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
@ -150,7 +150,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
||||
saSize = sizeof(sa6);
|
||||
memset(&sa6, 0, sizeof(sa6));
|
||||
sa6.sin6_family = AF_INET6;
|
||||
memcpy(sa6.sin6_addr.qt_s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.qt_s6_addr));
|
||||
memcpy(&sa6.sin6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr));
|
||||
}
|
||||
|
||||
char hbuf[NI_MAXHOST];
|
||||
@ -197,7 +197,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
||||
break;
|
||||
case AF_INET6: {
|
||||
QHostAddress addr;
|
||||
addr.setAddress(((qt_sockaddr_in6 *) p->ai_addr)->sin6_addr.qt_s6_addr);
|
||||
addr.setAddress(((sockaddr_in6 *) p->ai_addr)->sin6_addr.s6_addr);
|
||||
if (!addresses.contains(addr))
|
||||
addresses.append(addr);
|
||||
}
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <qurl.h>
|
||||
#include <private/qsystemlibrary_p.h>
|
||||
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef DWORD (WINAPI *PtrGetAdaptersInfo)(PIP_ADAPTER_INFO, PULONG);
|
||||
@ -86,8 +88,8 @@ 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) {
|
||||
address.setAddress(((qt_sockaddr_in6 *)sa)->sin6_addr.qt_s6_addr);
|
||||
int scope = ((qt_sockaddr_in6 *)sa)->sin6_scope_id;
|
||||
address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr);
|
||||
int scope = ((sockaddr_in6 *)sa)->sin6_scope_id;
|
||||
if (scope)
|
||||
address.setScopeId(QString::number(scope));
|
||||
} else
|
||||
|
@ -91,17 +91,6 @@ QT_BEGIN_NAMESPACE
|
||||
#define IF_TYPE_PPP 23
|
||||
|
||||
#endif
|
||||
// copied from qnativesocketengine_win.cpp
|
||||
struct qt_in6_addr {
|
||||
u_char qt_s6_addr[16];
|
||||
};
|
||||
typedef struct {
|
||||
short sin6_family; /* AF_INET6 */
|
||||
u_short sin6_port; /* Transport level port number */
|
||||
u_long sin6_flowinfo; /* IPv6 flow information */
|
||||
struct qt_in6_addr sin6_addr; /* IPv6 address */
|
||||
u_long sin6_scope_id; /* set of interfaces for a scope */
|
||||
} qt_sockaddr_in6;
|
||||
|
||||
// copied from MSDN online help
|
||||
typedef enum {
|
||||
|
@ -51,23 +51,12 @@
|
||||
# include <netinet/in.h>
|
||||
#else
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
# include <mswsock.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// Use our own defines and structs which we know are correct
|
||||
# define QT_SS_MAXSIZE 128
|
||||
# define QT_SS_ALIGNSIZE (sizeof(qint64))
|
||||
# define QT_SS_PAD1SIZE (QT_SS_ALIGNSIZE - sizeof (short))
|
||||
# define QT_SS_PAD2SIZE (QT_SS_MAXSIZE - (sizeof (short) + QT_SS_PAD1SIZE + QT_SS_ALIGNSIZE))
|
||||
struct qt_sockaddr_storage {
|
||||
short ss_family;
|
||||
char __ss_pad1[QT_SS_PAD1SIZE];
|
||||
qint64 __ss_align;
|
||||
char __ss_pad2[QT_SS_PAD2SIZE];
|
||||
};
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define QT_SOCKLEN_T int
|
||||
#define QT_SOCKOPTLEN_T int
|
||||
@ -103,25 +92,10 @@ typedef INT (WSAAPI *LPFN_WSASENDMSG)(SOCKET s, LPWSAMSG lpMsg, DWORD dwFlags,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// sockaddr_in6 size changed between old and new SDK
|
||||
// Only the new version is the correct one, so always
|
||||
// use this structure.
|
||||
struct qt_in6_addr {
|
||||
quint8 qt_s6_addr[16];
|
||||
};
|
||||
struct qt_sockaddr_in6 {
|
||||
short sin6_family; /* AF_INET6 */
|
||||
quint16 sin6_port; /* Transport level port number */
|
||||
quint32 sin6_flowinfo; /* IPv6 flow information */
|
||||
struct qt_in6_addr sin6_addr; /* IPv6 address */
|
||||
quint32 sin6_scope_id; /* set of interfaces for a scope */
|
||||
};
|
||||
|
||||
union qt_sockaddr {
|
||||
sockaddr a;
|
||||
sockaddr_in a4;
|
||||
qt_sockaddr_in6 a6;
|
||||
qt_sockaddr_storage storage;
|
||||
sockaddr_in6 a6;
|
||||
};
|
||||
|
||||
class QNativeSocketEnginePrivate;
|
||||
@ -302,13 +276,13 @@ public:
|
||||
|| address.protocol() == QAbstractSocket::AnyIPProtocol
|
||||
|| socketProtocol == QAbstractSocket::IPv6Protocol
|
||||
|| socketProtocol == QAbstractSocket::AnyIPProtocol) {
|
||||
memset(&aa->a6, 0, sizeof(qt_sockaddr_in6));
|
||||
memset(&aa->a6, 0, sizeof(sockaddr_in6));
|
||||
aa->a6.sin6_family = AF_INET6;
|
||||
aa->a6.sin6_scope_id = scopeIdFromString(address.scopeId());
|
||||
aa->a6.sin6_port = htons(port);
|
||||
Q_IPV6ADDR tmp = address.toIPv6Address();
|
||||
memcpy(&aa->a6.sin6_addr, &tmp, sizeof(tmp));
|
||||
*sockAddrSize = sizeof(qt_sockaddr_in6);
|
||||
*sockAddrSize = sizeof(sockaddr_in6);
|
||||
} else {
|
||||
memset(&aa->a, 0, sizeof(sockaddr_in));
|
||||
aa->a4.sin_family = AF_INET;
|
||||
|
@ -171,10 +171,10 @@ static QByteArray qt_prettyDebug(const char *data, int len, int maxLength)
|
||||
static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt_sockaddr *sa, quint16 *port, QHostAddress *address)
|
||||
{
|
||||
if (sa->a.sa_family == AF_INET6) {
|
||||
const qt_sockaddr_in6 *sa6 = &sa->a6;
|
||||
const sockaddr_in6 *sa6 = &sa->a6;
|
||||
Q_IPV6ADDR tmp;
|
||||
for (int i = 0; i < 16; ++i)
|
||||
tmp.c[i] = sa6->sin6_addr.qt_s6_addr[i];
|
||||
tmp.c[i] = sa6->sin6_addr.s6_addr[i];
|
||||
if (address) {
|
||||
QHostAddress a;
|
||||
a.setAddress(tmp);
|
||||
|
Loading…
Reference in New Issue
Block a user