INET Framework for OMNeT++/OMNEST
inet::serializer::TCPIPchecksum Class Reference

Calculates checksum. More...

#include <TCPIPchecksum.h>

Public Member Functions

 TCPIPchecksum ()
 

Static Public Member Functions

static uint16_t checksum (const void *addr, unsigned int count)
 
static uint16_t _checksum (const void *addr, unsigned int count)
 
static uint16_t checksum (unsigned int protocolId, const void *packet, unsigned int packetLength, const void *addr, unsigned int addrLength)
 

Detailed Description

Calculates checksum.

Constructor & Destructor Documentation

inet::serializer::TCPIPchecksum::TCPIPchecksum ( )
inline
33 {}

Member Function Documentation

uint16_t inet::serializer::TCPIPchecksum::_checksum ( const void *  addr,
unsigned int  count 
)
static

Referenced by checksum().

25 {
26  const unsigned char *addr = static_cast<const unsigned char *>(_addr);
27  uint32_t sum = 0;
28 
29  while (count > 1) {
30  sum += (addr[0] << 8) | addr[1];
31  addr += 2;
32  if (sum & 0x80000000)
33  sum = (sum & 0xFFFF) + (sum >> 16);
34  count -= 2;
35  }
36 
37  if (count)
38  sum += *(const uint8_t *)addr;
39 
40  while (sum >> 16)
41  sum = (sum & 0xFFFF) + (sum >> 16);
42 
43  return (uint16_t)sum;
44 }
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
uint16_t inet::serializer::TCPIPchecksum::checksum ( unsigned int  protocolId,
const void *  packet,
unsigned int  packetLength,
const void *  addr,
unsigned int  addrLength 
)
static
48 {
49  uint32_t sum = TCPIPchecksum::_checksum(packet, packetLength)
50  + TCPIPchecksum::_checksum(addr, addrLength) + packetLength + protocolId;
51 
52  while (sum >> 16)
53  sum = (sum & 0xFFFF) + (sum >> 16);
54 
55  return (uint16_t) ~sum;
56 }
static uint16_t _checksum(const void *addr, unsigned int count)
Definition: TCPIPchecksum.cc:24

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