summaryrefslogtreecommitdiff
path: root/base/inet.cc
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2004-10-01 19:48:33 -0400
committerNathan Binkert <binkertn@umich.edu>2004-10-01 19:48:33 -0400
commiteaf66f46588cdfd8a91b93821406e1d797c6d1fb (patch)
treeb2e418935f2730c5977600e414cecaf03a832faa /base/inet.cc
parent72276af49f1113649e97074b5b492ad7b5e25837 (diff)
downloadgem5-eaf66f46588cdfd8a91b93821406e1d797c6d1fb.tar.xz
fix some bugs in the headers and fix checksumming.
base/inet.cc: we can't use a uint16_t for the intermediate checksum values since there may be some bits that carry. the length that is added in the pseudo header is the length of the tcp portion only. base/inet.hh: silly me, the ip_hlen field is in terms of 4-byte words. when caclulating checksum, we're dealing with network byte order, so don't bother doing any byteswapping. --HG-- extra : convert_revision : 993e3413e9febea0ba2fb6ba8bf04c053cca15ed
Diffstat (limited to 'base/inet.cc')
-rw-r--r--base/inet.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/base/inet.cc b/base/inet.cc
index ac0758c1f..0b9e32854 100644
--- a/base/inet.cc
+++ b/base/inet.cc
@@ -46,16 +46,17 @@ eaddr_string(const uint8_t a[6])
uint16_t
IpHdr::ip_cksum() const
{
- uint16_t sum = ip_cksum_add(this, hlen(), 0);
- return ip_cksum_carry(sum);
+ int sum = ip_cksum_add(this, hlen(), 0);
+ sum = ip_cksum_carry(sum);
+ return sum;
}
uint16_t
IpHdr::tu_cksum() const
{
- uint16_t sum = ip_cksum_add(payload(), len() - hlen(), 0);
- sum = ip_cksum_add(&ip_src, 4, sum);
- sum = ip_cksum_add(&ip_dst, 4, sum);
- sum += htons(ip_p + ip_len);
- return ip_cksum_carry(sum);
+ int sum = ip_cksum_add(payload(), len() - hlen(), 0);
+ sum = ip_cksum_add(&ip_src, 8, sum); // source and destination
+ sum += htons(ip_p + len() - hlen());
+ sum = ip_cksum_carry(sum);
+ return sum;
}