Skip to content
Snippets Groups Projects
Commit 6687bbae authored by Martine Lenders's avatar Martine Lenders
Browse files

ng_inet_csum: add debug output

parent 50111372
No related branches found
No related tags found
No related merge requests found
......@@ -12,13 +12,28 @@
* @file
*/
#include <inttypes.h>
#include <stdio.h>
#include "od.h"
#include "net/ng_inet_csum.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
uint16_t ng_inet_csum(uint16_t sum, const uint8_t *buf, uint16_t len)
{
uint32_t csum = sum;
DEBUG("inet_sum: sum = 0x%04" PRIx16 ", len = %" PRIu16, sum, len);
#if ENABLE_DEBUG
#ifdef MODULE_OD
DEBUG(", buf:\n");
od_hex_dump(buf, len, OD_WIDTH_DEFAULT);
#else
DEBUG(", buf output only with od module\n");
#endif
#endif
for (int i = 0; i < (len >> 1); buf += 2, i++) {
csum += (*buf << 8) + *(buf + 1); /* group bytes by 16-byte words
* and add them*/
......@@ -30,6 +45,8 @@ uint16_t ng_inet_csum(uint16_t sum, const uint8_t *buf, uint16_t len)
csum += csum >> 16;
DEBUG("inet_sum: new sum = 0x%04" PRIx32 "\n", csum & 0xffff);
return (csum & 0xffff);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment