From 065de9ace593e41a59ed21b713c5fffbec759d50 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 25 Sep 2018 22:57:30 +0200 Subject: ip/icmp checksum fix --- net/icmp.c | 6 +++--- net/inet.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'net') diff --git a/net/icmp.c b/net/icmp.c index 54dc67b..6f5f14f 100644 --- a/net/icmp.c +++ b/net/icmp.c @@ -26,8 +26,8 @@ bool icmp_reply(struct netdev *dev,struct eth_hdr *hdr) data->csum=0; ipv4->csum=0; - data->csum=htons(checksum(data,ipv4->len-ipv4->ihl*4)); - ipv4->csum=htons(checksum(ipv4,ntohs(ipv4->len))); + data->csum=(checksum(data,ntohs(ipv4->len)-ipv4->ihl*4)); + ipv4->csum=(checksum(ipv4,ntohs(ipv4->len))); dev->transmit(hdr,ntohs(ipv4->len)+14); // 14bytes for link2 @@ -43,7 +43,7 @@ bool icmp_incoming(struct netdev *dev,struct eth_hdr *hdr) klog ("icmp code=%d",data->code); klog ("icmp csum=0x%04x",ntohs(data->csum)); data->csum=0; - klog("expected checksum = 0x%04X",checksum(data,ipv4->len-ipv4->ihl*4)); + klog("expected checksum = 0x%04X",checksum(data,ntohs(ipv4->len)-ipv4->ihl*4)); if(data->type==ICMP_ECHO_REQUEST) // echo request { diff --git a/net/inet.c b/net/inet.c index f7cc2a6..67895d5 100644 --- a/net/inet.c +++ b/net/inet.c @@ -21,7 +21,8 @@ uint16_t checksum(void *addr, int count) while( count > 1 ) { /* This is the inner loop */ - sum += ntohs(* ptr++); + //sum += ntohs(* ptr++); + sum += *ptr++; count -= 2; } -- cgit v1.2.3