mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
net_help: prefix csum properly and add documentation
This commit is contained in:
parent
4d82c2c646
commit
c9219b87d6
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "net_help.h"
|
#include "net_help.h"
|
||||||
|
|
||||||
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)
|
uint16_t net_help_csum(uint16_t sum, uint8_t *buf, uint16_t len)
|
||||||
{
|
{
|
||||||
int count = len >> 1;
|
int count = len >> 1;
|
||||||
|
|
||||||
|
@ -65,7 +65,20 @@ static inline uint64_t NTOHLL(uint64_t a)
|
|||||||
return byteorder_ntohll(*(network_uint64_t *) &a);
|
return byteorder_ntohll(*(network_uint64_t *) &a);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len);
|
/**
|
||||||
|
* @brief Computes the Internet Checksum for *buf* with initial value *init*
|
||||||
|
*
|
||||||
|
* @see <a href="https://tools.ietf.org/html/rfc1071">
|
||||||
|
* RFC 1071
|
||||||
|
* </a>
|
||||||
|
*
|
||||||
|
* @param[in] init Initial value for the checksum (0 in most cases)
|
||||||
|
* @param[in] buf A byte array to calculate the checksum of
|
||||||
|
* @param[in] buf_len Length of *buf*
|
||||||
|
*
|
||||||
|
* @return The Internet Checksum of *buf* with initial value *init*
|
||||||
|
*/
|
||||||
|
uint16_t net_help_csum(uint16_t init, uint8_t *buf, uint16_t buf_len);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1437,8 +1437,8 @@ uint16_t icmpv6_csum(ipv6_hdr_t *ipv6_buf, icmpv6_hdr_t *icmpv6_buf)
|
|||||||
icmpv6_buf->checksum = 0;
|
icmpv6_buf->checksum = 0;
|
||||||
sum = len + IPV6_PROTO_NUM_ICMPV6;
|
sum = len + IPV6_PROTO_NUM_ICMPV6;
|
||||||
|
|
||||||
sum = csum(sum, (uint8_t *)&ipv6_buf->srcaddr, 2 * sizeof(ipv6_addr_t));
|
sum = net_help_csum(sum, (uint8_t *)&ipv6_buf->srcaddr, 2 * sizeof(ipv6_addr_t));
|
||||||
sum = csum(sum, (uint8_t *)icmpv6_buf, len);
|
sum = net_help_csum(sum, (uint8_t *)icmpv6_buf, len);
|
||||||
|
|
||||||
return (sum == 0) ? 0 : ~HTONS(sum);
|
return (sum == 0) ? 0 : ~HTONS(sum);
|
||||||
}
|
}
|
||||||
|
@ -820,7 +820,7 @@ uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t
|
|||||||
&ipv6_header->destaddr),
|
&ipv6_header->destaddr),
|
||||||
len, buf, proto);
|
len, buf, proto);
|
||||||
sum = len + proto;
|
sum = len + proto;
|
||||||
sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
|
sum = net_help_csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
|
||||||
sum = csum(sum, buf, len);
|
sum = net_help_csum(sum, buf, len);
|
||||||
return (sum == 0) ? 0xffff : HTONS(sum);
|
return (sum == 0) ? 0xffff : HTONS(sum);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header)
|
|||||||
uint16_t len = NTOHS(udp_header->length);
|
uint16_t len = NTOHS(udp_header->length);
|
||||||
|
|
||||||
sum = len + IPPROTO_UDP;
|
sum = len + IPPROTO_UDP;
|
||||||
sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
|
sum = net_help_csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
|
||||||
sum = csum(sum, (uint8_t *)udp_header, len);
|
sum = net_help_csum(sum, (uint8_t *)udp_header, len);
|
||||||
return (sum == 0) ? 0xffff : HTONS(sum);
|
return (sum == 0) ? 0xffff : HTONS(sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user