Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Bugfix(collateral): Fixed TCP/UDP checksum on big-endian platforms; c…
Browse files Browse the repository at this point in the history
…ollateral of changes made in IPv4/IPv6 pseudo header cksum for variable fields feature
  • Loading branch information
pstavirs committed Jun 6, 2015
1 parent d677b09 commit 24d341c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions common/ip4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,14 +813,14 @@ quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
{
quint32 sum = 0;
QByteArray fv = protocolFrameValue(streamIndex);
const char *p = fv.constData();
const quint8 *p = (quint8*) fv.constData();

sum += *((quint16*)(p + 12)); // src-ip hi
sum += *((quint16*)(p + 14)); // src-ip lo
sum += *((quint16*)(p + 16)); // dst-ip hi
sum += *((quint16*)(p + 18)); // dst-ip lo
sum += qToBigEndian((quint16) protocolFramePayloadSize()); // len
sum += *((quint8*) (p + 9)) << 8; // proto
sum += qToBigEndian((quint16) *(p + 9)); // proto

while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
Expand Down
4 changes: 2 additions & 2 deletions common/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,13 @@ quint32 Ip6Protocol::protocolFrameCksum(int streamIndex,
{
quint32 sum = 0;
QByteArray fv = protocolFrameValue(streamIndex);
const char *p = fv.constData();
const quint8 *p = (quint8*) fv.constData();

// src-ip, dst-ip
for (int i = 8; i < fv.size(); i+=2)
sum += *((quint16*)(p + i));
sum += *((quint16*)(p + 4)); // payload len
sum += *((quint8*) (p + 6)) << 8; // proto
sum += qToBigEndian((quint16) *(p + 6)); // proto

while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
Expand Down

0 comments on commit 24d341c

Please sign in to comment.