diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-03-16 00:09:31 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-03-16 00:09:31 +0000 |
commit | acaab5c7cb917271d8f1119b8f939b88c86b80fd (patch) | |
tree | f447dacc2f57442d1df8ee855c2f711bc39260f5 /nuttx/net/uip | |
parent | e7fa349439a23696eac35a4a74c27f1357ec6a97 (diff) | |
download | px4-nuttx-acaab5c7cb917271d8f1119b8f939b88c86b80fd.tar.gz px4-nuttx-acaab5c7cb917271d8f1119b8f939b88c86b80fd.tar.bz2 px4-nuttx-acaab5c7cb917271d8f1119b8f939b88c86b80fd.zip |
Fix calculation of checksum on outgoing ping responses
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1617 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/uip')
-rw-r--r-- | nuttx/net/uip/uip_chksum.c | 6 | ||||
-rw-r--r-- | nuttx/net/uip/uip_icmpinput.c | 20 | ||||
-rw-r--r-- | nuttx/net/uip/uip_icmpsend.c | 2 |
3 files changed, 15 insertions, 13 deletions
diff --git a/nuttx/net/uip/uip_chksum.c b/nuttx/net/uip/uip_chksum.c index defb5b479..45e8894b3 100644 --- a/nuttx/net/uip/uip_chksum.c +++ b/nuttx/net/uip/uip_chksum.c @@ -229,11 +229,11 @@ uint16 uip_udpchksum(struct uip_driver_s *dev) /* Calculate the checksum of the ICMP message */ -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) -uint16 uip_icmpchksum(struct uip_driver_s *dev) +#if defined(CONFIG_NET_ICMP) +uint16 uip_icmpchksum(struct uip_driver_s *dev, int len) { struct uip_icmpip_hdr *picmp = ICMPBUF; - return uip_chksum((uint16*)&picmp->type, dev->d_sndlen); + return uip_chksum((uint16*)&picmp->type, len); } #endif diff --git a/nuttx/net/uip/uip_icmpinput.c b/nuttx/net/uip/uip_icmpinput.c index 52352c700..f2edcbcb5 100644 --- a/nuttx/net/uip/uip_icmpinput.c +++ b/nuttx/net/uip/uip_icmpinput.c @@ -131,22 +131,24 @@ void uip_icmpinput(struct uip_driver_s *dev) } #endif - picmp->type = ICMP_ECHO_REPLY; + /* Change the ICMP type */ - if (picmp->icmpchksum >= HTONS(0xffff - (ICMP_ECHO_REPLY << 8))) - { - picmp->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8) + 1; - } - else - { - picmp->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8); - } + picmp->type = ICMP_ECHO_REPLY; /* Swap IP addresses. */ uiphdr_ipaddr_copy(picmp->destipaddr, picmp->srcipaddr); uiphdr_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr); + /* Recalculate the ICMP checksum */ + + picmp->icmpchksum = 0; + picmp->icmpchksum = ~uip_icmpchksum(dev, (((uint16)picmp->len[0] << 8) | (uint16)picmp->len[1]) - UIP_IPH_LEN); + if (picmp->icmpchksum == 0) + { + picmp->icmpchksum = 0xffff; + } + nvdbg("Outgoing ICMP packet length: %d (%d)\n", dev->d_len, (picmp->len[0] << 8) | picmp->len[1]); diff --git a/nuttx/net/uip/uip_icmpsend.c b/nuttx/net/uip/uip_icmpsend.c index 6acbf3176..0c3784e95 100644 --- a/nuttx/net/uip/uip_icmpsend.c +++ b/nuttx/net/uip/uip_icmpsend.c @@ -150,7 +150,7 @@ void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr) /* Calculate the ICMP checksum. */ picmp->icmpchksum = 0; - picmp->icmpchksum = ~(uip_icmpchksum(dev)); + picmp->icmpchksum = ~(uip_icmpchksum(dev, dev->d_sndlen)); if (picmp->icmpchksum == 0) { picmp->icmpchksum = 0xffff; |