CS144's user-space TCP library
Public Member Functions | Private Attributes | List of all members
InternetChecksum Class Reference

The internet checksum algorithm. More...

#include <util.hh>

Public Member Functions

 InternetChecksum (const uint32_t initial_sum=0)
void add (std::string_view data)
uint16_t value () const

Private Attributes

bool _parity {}
uint32_t _sum

Detailed Description

The internet checksum algorithm.

Definition at line 55 of file util.hh.

Constructor & Destructor Documentation

◆ InternetChecksum()

InternetChecksum::InternetChecksum ( const uint32_t  initial_sum = 0)
This class returns the checksum in host byte order. See https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html for rationale

This class can be used to either check or compute an Internet checksum (e.g., for an IP datagram header or a TCP segment).

The Internet checksum is defined such that evaluating inet_cksum() on a TCP segment (IP datagram, etc) containing a correct checksum header will return zero. In other words, if you read a correct TCP segment off the wire and pass it untouched to inet_cksum(), the return value will be 0.

Meanwhile, to compute the checksum for an outgoing TCP segment (IP datagram, etc.), you must first set the checksum header to zero, then call inet_cksum(), and finally set the checksum header to the return value.

For more information, see the Wikipedia page on the Internet checksum, and consult the IP and TCP RFCs.

Definition at line 87 of file util.cc.

Member Function Documentation

◆ add()

void InternetChecksum::add ( std::string_view  data)

Definition at line 89 of file util.cc.

◆ value()

uint16_t InternetChecksum::value ( ) const

Definition at line 100 of file util.cc.

Member Data Documentation

◆ _parity

bool InternetChecksum::_parity {}

Definition at line 58 of file util.hh.

◆ _sum

uint32_t InternetChecksum::_sum

Definition at line 57 of file util.hh.

The documentation for this class was generated from the following files: