diff --git a/sys/net/crosslayer/net_help/net_help.c b/sys/net/crosslayer/net_help/net_help.c index cc33e1e196..7ffc29f1cb 100644 --- a/sys/net/crosslayer/net_help/net_help.c +++ b/sys/net/crosslayer/net_help/net_help.c @@ -19,19 +19,7 @@ #include "net_help.h" -void printArrayRange(uint8_t *array, uint16_t len, char *str) -{ - 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) +uint16_t net_help_csum(uint16_t sum, uint8_t *buf, uint16_t len) { int count = len >> 1; diff --git a/sys/net/include/net_help.h b/sys/net/include/net_help.h index f5d359bf16..c743ef8110 100644 --- a/sys/net/include/net_help.h +++ b/sys/net/include/net_help.h @@ -65,10 +65,20 @@ static inline uint64_t NTOHLL(uint64_t a) return byteorder_ntohll(*(network_uint64_t *) &a); } -#define CMP_IPV6_ADDR(a, b) (memcmp(a, b, 16)) - -uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len); -void printArrayRange(uint8_t *array, uint16_t len, char *str); +/** + * @brief Computes the Internet Checksum for *buf* with initial value *init* + * + * @see + * RFC 1071 + * + * + * @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 } diff --git a/sys/net/network_layer/sixlowpan/icmp.c b/sys/net/network_layer/sixlowpan/icmp.c index 1490f35cb9..3a8bc8989c 100644 --- a/sys/net/network_layer/sixlowpan/icmp.c +++ b/sys/net/network_layer/sixlowpan/icmp.c @@ -1437,8 +1437,8 @@ uint16_t icmpv6_csum(ipv6_hdr_t *ipv6_buf, icmpv6_hdr_t *icmpv6_buf) icmpv6_buf->checksum = 0; sum = len + IPV6_PROTO_NUM_ICMPV6; - sum = 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 *)&ipv6_buf->srcaddr, 2 * sizeof(ipv6_addr_t)); + sum = net_help_csum(sum, (uint8_t *)icmpv6_buf, len); return (sum == 0) ? 0 : ~HTONS(sum); } diff --git a/sys/net/network_layer/sixlowpan/ip.c b/sys/net/network_layer/sixlowpan/ip.c index c0955827ff..8ad2ccb3d0 100644 --- a/sys/net/network_layer/sixlowpan/ip.c +++ b/sys/net/network_layer/sixlowpan/ip.c @@ -820,7 +820,7 @@ uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t &ipv6_header->destaddr), len, buf, proto); sum = len + proto; - sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); - sum = csum(sum, buf, len); + sum = net_help_csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); + sum = net_help_csum(sum, buf, len); return (sum == 0) ? 0xffff : HTONS(sum); } diff --git a/sys/net/transport_layer/tcp/tcp.c b/sys/net/transport_layer/tcp/tcp.c index 0e636c5fb5..88dc6584f3 100644 --- a/sys/net/transport_layer/tcp/tcp.c +++ b/sys/net/transport_layer/tcp/tcp.c @@ -71,18 +71,6 @@ void printTCPHeader(tcp_hdr_t *tcp_header) 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) { printf("FLAGS: "); @@ -744,8 +732,6 @@ void *tcp_packet_handler(void *arg) else { printf("Wrong checksum (%x) or no corresponding socket found!\n", chksum); - printArrayRange(((uint8_t *)ipv6_header), IPV6_HDR_LEN + - NTOHS(ipv6_header->length), "Incoming"); print_tcp_status(INC_PACKET, ipv6_header, tcp_header, &tcp_socket->socket_values); } diff --git a/sys/net/transport_layer/udp/udp.c b/sys/net/transport_layer/udp/udp.c index 3bf2b48112..230ac61674 100644 --- a/sys/net/transport_layer/udp/udp.c +++ b/sys/net/transport_layer/udp/udp.c @@ -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); sum = len + IPPROTO_UDP; - sum = 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 *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); + sum = net_help_csum(sum, (uint8_t *)udp_header, len); return (sum == 0) ? 0xffff : HTONS(sum); }