IN_CKSUM(9) | Kernel Developer's Manual | IN_CKSUM(9) |
uint16_t
in4_cksum(struct mbuf *m, uint8_t nxt, int off, int len);
uint16_t
in6_cksum(struct mbuf *m, uint8_t nxt, int off, int len);
If the nxt parameter is non-zero, it is assumed to be an IP protocol number. It is also assumed that the data within m starts with an IP header, and the transport-layer header starts at off; a pseudo-header is constructed as specified in RFC768 and RFC793, and the pseudo-header is prepended to the data covered by the checksum.
The in6_cksum() function is similar; if nxt is non-zero, it is assumed that m starts with an IPv6 header, and that the transport-layer header starts after off bytes.
The in_cksum() function is equivalent to in4_cksum(m, 0, 0, len).
These functions are always performance critical and should be reimplemented in assembler or optimized C for each platform; when available, use of repeated full-width add-with-carry followed by reduction of the sum to a 16 bit width usually leads to best results. See RFC's 1071, 1141, 1624, and 1936 for more information about efficient computation of the internet checksum.
May 22, 2001 | NetBSD 6.1 |