diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-09-28 11:58:51 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-09-28 11:58:51 +0000 |
| commit | d8c86658f117f2cdf2047a2f02daf8cde3eae7da (patch) | |
| tree | 9eeb47779401a1ec6bc65bdf39f268fbb501950b /src/QXmppStun.cpp | |
| parent | e04f2768192101621ab692a3a0811b674c176ae2 (diff) | |
| download | qxmpp-d8c86658f117f2cdf2047a2f02daf8cde3eae7da.tar.gz | |
fix encoding of IPv6 addreses in STUN packets
Diffstat (limited to 'src/QXmppStun.cpp')
| -rw-r--r-- | src/QXmppStun.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/QXmppStun.cpp b/src/QXmppStun.cpp index 564429cd..78a331e3 100644 --- a/src/QXmppStun.cpp +++ b/src/QXmppStun.cpp @@ -103,19 +103,25 @@ static bool decodeAddress(QDataStream &stream, quint16 a_length, QHostAddress &a static void encodeAddress(QDataStream &stream, quint16 type, const QHostAddress &address, quint16 port) { - stream << type; - stream << quint16(8); - stream << quint8(0); + const quint8 reserved = 0; if (address.protocol() == QAbstractSocket::IPv4Protocol) { + stream << type; + stream << quint16(8); + stream << reserved; stream << quint8(STUN_IPV4); stream << port; stream << address.toIPv4Address(); } else if (address.protocol() == QAbstractSocket::IPv6Protocol) { + stream << type; + stream << quint16(20); + stream << reserved; stream << quint8(STUN_IPV6); stream << port; Q_IPV6ADDR addr = address.toIPv6Address(); stream.writeRawData((char*)&addr, sizeof(addr)); + } else { + qWarning("Cannot write STUN attribute for unknown IP version"); } } @@ -452,15 +458,18 @@ QByteArray QXmppStunMessage::encode(const QString &password) const (xorMappedHost.protocol() == QAbstractSocket::IPv4Protocol || xorMappedHost.protocol() == QAbstractSocket::IPv6Protocol)) { + const quint8 reserved = 0; stream << quint16(XorMappedAddress); - stream << quint16(8); - stream << quint8(0); if (xorMappedHost.protocol() == QAbstractSocket::IPv4Protocol) { + stream << quint16(8); + stream << reserved; stream << quint8(STUN_IPV4); stream << quint16(xorMappedPort ^ (STUN_MAGIC >> 16)); stream << quint32(xorMappedHost.toIPv4Address() ^ STUN_MAGIC); } else { + stream << quint16(20); + stream << reserved; stream << quint8(STUN_IPV6); stream << quint16(xorMappedPort ^ (STUN_MAGIC >> 16)); Q_IPV6ADDR addr = xorMappedHost.toIPv6Address(); |
