Skip to content

Commit 62355e3

Browse files
net: IP4 Packet checksum is now big endian, checksum getter for TCP packet
1 parent 1ff0477 commit 62355e3

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

api/net/ip4/packet_ip4.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace net {
8686

8787
/** Get the IP header checksum field as-is */
8888
uint16_t ip_checksum() const noexcept
89-
{ return ntohs(ip_header().check); }
89+
{ return ip_header().check; }
9090

9191
/** Get source address */
9292
const ip4::Addr& ip_src() const noexcept
@@ -171,7 +171,7 @@ namespace net {
171171

172172
/** Set IP header checksum field directly */
173173
void set_ip_checksum(uint16_t sum) noexcept
174-
{ ip_header().check = ntohs(sum); }
174+
{ ip_header().check = sum; }
175175

176176
/** Calculate and set IP header checksum field */
177177
void set_ip_checksum() noexcept {

api/net/tcp/packet.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class Packet : public PacketIP4 {
8484
inline uint16_t win() const
8585
{ return ntohs(tcp_header().window_size); }
8686

87+
uint16_t tcp_checksum() const noexcept
88+
{ return tcp_header().checksum; }
89+
8790
inline Socket source() const
8891
{ return Socket{ip_src(), src_port()}; }
8992

0 commit comments

Comments
 (0)