diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2016-07-06 20:35:16 -0400 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2016-07-06 20:35:16 -0400 |
commit | e6cec2f2553a4187a09d92f3a79c0cc0b5049b79 (patch) | |
tree | 24b2e9b9c53d2628d48857695cdd2b29d55c9e31 /src/checksum.h | |
parent | c68c67ce7d88dcfc9db29e572d60e1c43ddb2519 (diff) | |
download | udpastcp-e6cec2f2553a4187a09d92f3a79c0cc0b5049b79.tar.xz udpastcp-e6cec2f2553a4187a09d92f3a79c0cc0b5049b79.zip |
Add IPv4 support.
Diffstat (limited to 'src/checksum.h')
-rw-r--r-- | src/checksum.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/checksum.h b/src/checksum.h index 7d4a003..700ee1a 100644 --- a/src/checksum.h +++ b/src/checksum.h @@ -1,5 +1,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); |