From b626a5859abef9a1b47ba02ffab0fd8d08f79a21 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 9 Aug 2015 21:56:26 -0700 Subject: 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 --- src/network/socket/qnativesocketengine_p.h | 34 +++----------------------- src/network/socket/qnativesocketengine_win.cpp | 4 +-- 2 files changed, 6 insertions(+), 32 deletions(-) (limited to 'src/network/socket') diff --git a/src/network/socket/qnativesocketengine_p.h b/src/network/socket/qnativesocketengine_p.h index 966f44f774..0fa1d8f96e 100644 --- a/src/network/socket/qnativesocketengine_p.h +++ b/src/network/socket/qnativesocketengine_p.h @@ -51,23 +51,12 @@ # include #else # include +# include # include #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; diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index 5e198098df..2e905ad610 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -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); -- cgit v1.2.3