mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #2019 from authmillenon/cleanup-net_help
net_help: Cleanup
This commit is contained in:
commit
4d674ef107
@ -19,19 +19,7 @@
|
|||||||
|
|
||||||
#include "net_help.h"
|
#include "net_help.h"
|
||||||
|
|
||||||
void printArrayRange(uint8_t *array, uint16_t len, char *str)
|
uint16_t net_help_csum(uint16_t sum, uint8_t *buf, uint16_t len)
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
printf("-------------%s-------------\n", str);
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
printf("%#x ", *(array + i));
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n-----------%u-------------\n", len);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len)
|
|
||||||
{
|
{
|
||||||
int count = len >> 1;
|
int count = len >> 1;
|
||||||
|
|
||||||
|
@ -65,10 +65,20 @@ static inline uint64_t NTOHLL(uint64_t a)
|
|||||||
return byteorder_ntohll(*(network_uint64_t *) &a);
|
return byteorder_ntohll(*(network_uint64_t *) &a);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CMP_IPV6_ADDR(a, b) (memcmp(a, b, 16))
|
/**
|
||||||
|
* @brief Computes the Internet Checksum for *buf* with initial value *init*
|
||||||
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len);
|
*
|
||||||
void printArrayRange(uint8_t *array, uint16_t len, char *str);
|
* @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);
|
||||||
}
|
}
|
||||||
|
@ -71,18 +71,6 @@ void printTCPHeader(tcp_hdr_t *tcp_header)
|
|||||||
printf("END: TCP HEADER\n");
|
printf("END: TCP HEADER\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void printArrayRange_tcp(uint8_t *udp_header, uint16_t len)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
printf("-------------MEMORY-------------\n");
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
printf("%#x ", *(udp_header + i));
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("-------------MEMORY-------------\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_tcp_flags(tcp_hdr_t *tcp_header)
|
void print_tcp_flags(tcp_hdr_t *tcp_header)
|
||||||
{
|
{
|
||||||
printf("FLAGS: ");
|
printf("FLAGS: ");
|
||||||
@ -744,8 +732,6 @@ void *tcp_packet_handler(void *arg)
|
|||||||
else {
|
else {
|
||||||
printf("Wrong checksum (%x) or no corresponding socket found!\n",
|
printf("Wrong checksum (%x) or no corresponding socket found!\n",
|
||||||
chksum);
|
chksum);
|
||||||
printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN +
|
|
||||||
NTOHS(ipv6_header->length), "Incoming");
|
|
||||||
print_tcp_status(INC_PACKET, ipv6_header, tcp_header,
|
print_tcp_status(INC_PACKET, ipv6_header, tcp_header,
|
||||||
&tcp_socket->socket_values);
|
&tcp_socket->socket_values);
|
||||||
}
|
}
|
||||||
|
@ -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