diff --git a/src/packet.cpp b/src/packet.cpp index 62ac7ed5..9e34d707 100755 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -596,6 +596,20 @@ QByteArray Packet::HEXtoByteArray(QString thehex) } +QString Packet::removeIPv6Mapping(QHostAddress ipv6) +{ + bool ok; + quint32 ipv4 = ipv6.toIPv4Address(&ok); + + if(ok) { + QHostAddress new_ipv4(ipv4); + return new_ipv4.toString(); + } else { + return ipv6.toString(); + } + +} + QString Packet::ASCIITohex(QString &ascii) { if(ascii.isEmpty()) diff --git a/src/packet.h b/src/packet.h index 339ea529..7b7ee2dd 100755 --- a/src/packet.h +++ b/src/packet.h @@ -52,6 +52,7 @@ class Packet static QString hexToASCII(QString &hex); static QString byteArrayToHex(QByteArray data); static QByteArray HEXtoByteArray(QString thehex); + static QString removeIPv6Mapping(QHostAddress ipv6); QByteArray getByteArray(); QString asciiString(); diff --git a/src/packetnetwork.cpp b/src/packetnetwork.cpp index 9d37c753..c372ae7d 100755 --- a/src/packetnetwork.cpp +++ b/src/packetnetwork.cpp @@ -197,7 +197,7 @@ void PacketNetwork::readPendingDatagrams() udpPacket.timestamp = QDateTime::currentDateTime(); udpPacket.name = udpPacket.timestamp.toString(DATETIMEFORMAT); udpPacket.tcpOrUdp = "UDP"; - udpPacket.fromIP = sender.toString(); + udpPacket.fromIP = Packet::removeIPv6Mapping(sender); udpPacket.toIP = "You"; udpPacket.port = getUDPPort(); udpPacket.fromPort = senderPort; @@ -214,7 +214,7 @@ void PacketNetwork::readPendingDatagrams() udpPacket.name = udpPacket.timestamp.toString(DATETIMEFORMAT); udpPacket.tcpOrUdp = "UDP"; udpPacket.fromIP = "You (Response)"; - udpPacket.toIP = sender.toString(); + udpPacket.toIP = Packet::removeIPv6Mapping(sender); udpPacket.port = senderPort; udpPacket.fromPort = getUDPPort(); udpPacket.hexString = responseData; diff --git a/src/tcpthread.cpp b/src/tcpthread.cpp index 9a332814..f4bdd511 100755 --- a/src/tcpthread.cpp +++ b/src/tcpthread.cpp @@ -69,7 +69,7 @@ void TCPThread::writeResponse(QTcpSocket *sock, Packet tcpPacket) { tcpPacketreply.name = "Reply to " + tcpPacket.timestamp.toString(DATETIMEFORMAT); tcpPacketreply.tcpOrUdp = "TCP"; tcpPacketreply.fromIP = "You (Response)"; - tcpPacketreply.toIP = sock->peerAddress().toString(); + tcpPacketreply.toIP = Packet::removeIPv6Mapping(sock->peerAddress()); tcpPacketreply.port = sock->peerPort(); tcpPacketreply.fromPort = sock->localPort(); QByteArray data = Packet::HEXtoByteArray(responseData); @@ -89,6 +89,7 @@ void TCPThread::closeConnection() clientConnection->close(); } + void TCPThread::run() { @@ -170,7 +171,9 @@ void TCPThread::run() tcpRCVPacket.timestamp = QDateTime::currentDateTime(); tcpRCVPacket.name = QDateTime::currentDateTime().toString(DATETIMEFORMAT); tcpRCVPacket.tcpOrUdp = "TCP"; - tcpRCVPacket.fromIP = clientConnection->peerAddress().toString(); + tcpRCVPacket.fromIP = Packet::removeIPv6Mapping(clientConnection->peerAddress()); + + QDEBUGVAR(tcpRCVPacket.fromIP); tcpRCVPacket.toIP = "You"; tcpRCVPacket.port = sendPacket.fromPort; @@ -194,7 +197,9 @@ void TCPThread::run() tcpPacket.timestamp = QDateTime::currentDateTime(); tcpPacket.name = QDateTime::currentDateTime().toString(DATETIMEFORMAT); tcpPacket.tcpOrUdp = "TCP"; - tcpPacket.fromIP = clientConnection->peerAddress().toString(); + tcpPacket.fromIP = Packet::removeIPv6Mapping(clientConnection->peerAddress()); + QDEBUGVAR(tcpPacket.fromIP); + tcpPacket.toIP = "You"; tcpPacket.port = sendPacket.fromPort; tcpPacket.fromPort = clientConnection->peerPort(); @@ -291,7 +296,7 @@ void TCPThread::run() tcpPacket.timestamp = QDateTime::currentDateTime(); tcpPacket.name = tcpPacket.timestamp.toString(DATETIMEFORMAT); tcpPacket.tcpOrUdp = "TCP"; - tcpPacket.fromIP = sock.peerAddress().toString(); + tcpPacket.fromIP = Packet::removeIPv6Mapping(sock.peerAddress()); tcpPacket.toIP = "You"; tcpPacket.port = sock.localPort(); tcpPacket.fromPort = sock.peerPort();