summaryrefslogtreecommitdiff
path: root/src/checksum.h
blob: 700ee1aa7b123aaa4efbebeb9171785c2af2ff42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <netinet/in.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>

/* calculates the checksum of len bytes at buff when combined with wsum.
 * return value is already in network order, but must be inverted before
 * sending.
 * example: hdr.th_sum = csum_partial(data, len, csum_partial(hdr, hdrlen, 0));
 */
uint16_t csum_partial(const void *buff, int len, uint16_t wsum);

/* calculates the checksum of a sockaddr_in or sockaddr_in6.
 * if incl_port is set then the sin_port will be included.
 * otherwise identical to csum_partial.
 */
uint16_t csum_sockaddr_partial(const struct sockaddr *addr, int incl_port, uint16_t wsum);