Skip to content

Commit

Permalink
ipv6 text mapping cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dannagle committed Dec 12, 2015
1 parent 38d83a8 commit 292cd96
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions src/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/packetnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/tcpthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -89,6 +89,7 @@ void TCPThread::closeConnection()
clientConnection->close();
}


void TCPThread::run()
{

Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 292cd96

Please sign in to comment.