lwIP  2.0.2
Lightweight IP stack
inet_chksum.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"

Macros

#define SWAP_BYTES_IN_WORD(w)   (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)
 
#define FOLD_U32T(u)   (((u) >> 16) + ((u) & 0x0000ffffUL))
 

Functions

u16_t inet_chksum_pbuf (struct pbuf *p)
 
u16_t ip6_chksum_pseudo (struct pbuf *p, u8_t proto, u16_t proto_len, const ip6_addr_t *src, const ip6_addr_t *dest)
 
u16_t ip6_chksum_pseudo_partial (struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest)
 

Detailed Description

IP checksum calculation functions

Macro Definition Documentation

◆ FOLD_U32T

#define FOLD_U32T (   u)    (((u) >> 16) + ((u) & 0x0000ffffUL))

Split an u32_t in two u16_ts and add them up

◆ SWAP_BYTES_IN_WORD

#define SWAP_BYTES_IN_WORD (   w)    (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)

Swap the bytes in an u16_t: much like lwip_htons() for little-endian

Function Documentation

◆ inet_chksum_pbuf()

u16_t inet_chksum_pbuf ( struct pbuf p)

Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used).

Parameters
ppbuf chain over that the checksum should be calculated
Returns
checksum (as u16_t) to be saved directly in the protocol header

◆ ip6_chksum_pseudo()

u16_t ip6_chksum_pseudo ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
const ip6_addr_t src,
const ip6_addr_t dest 
)

Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain. IPv6 addresses are expected to be in network byte order.

Parameters
pchain of pbufs over that a checksum should be calculated (ip data part)
protoipv6 protocol/next header (used for checksum of pseudo header)
proto_lenlength of the ipv6 payload (used for checksum of pseudo header)
srcsource ipv6 address (used for checksum of pseudo header)
destdestination ipv6 address (used for checksum of pseudo header)
Returns
checksum (as u16_t) to be saved directly in the protocol header

◆ ip6_chksum_pseudo_partial()

u16_t ip6_chksum_pseudo_partial ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
u16_t  chksum_len,
const ip6_addr_t src,
const ip6_addr_t dest 
)

Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain. IPv6 addresses are expected to be in network byte order. Will only compute for a portion of the payload.

Parameters
pchain of pbufs over that a checksum should be calculated (ip data part)
protoipv6 protocol/next header (used for checksum of pseudo header)
proto_lenlength of the ipv6 payload (used for checksum of pseudo header)
chksum_lennumber of payload bytes used to compute chksum
srcsource ipv6 address (used for checksum of pseudo header)
destdestination ipv6 address (used for checksum of pseudo header)
Returns
checksum (as u16_t) to be saved directly in the protocol header