Fix calculation of checksum on outgoing ping responses
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1617 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
e95edf592b
commit
bc89420c34
|
@ -657,3 +657,4 @@
|
|||
|
||||
* examples/nsh: A debug option was left on that can (and does) cause
|
||||
infinite loops and stack overflows.
|
||||
* net/uip: Correct calculation of checksum on ICMP ping response.
|
||||
|
|
|
@ -1348,6 +1348,7 @@ nuttx-0.4.4 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
|||
|
||||
* examples/nsh: A debug option was left on that can (and does) cause
|
||||
infinite loops and stack overflows.
|
||||
* net/uip: Correct calculation of checksum on ICMP ping response.
|
||||
|
||||
pascal-0.1.3 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
|
||||
|
|
|
@ -366,7 +366,7 @@ extern uint16 uip_ipchksum(struct uip_driver_s *dev);
|
|||
extern uint16 uip_tcpchksum(struct uip_driver_s *dev);
|
||||
|
||||
extern uint16 uip_udpchksum(struct uip_driver_s *dev);
|
||||
extern uint16 uip_icmpchksum(struct uip_driver_s *dev);
|
||||
extern uint16 uip_icmpchksum(struct uip_driver_s *dev, int len);
|
||||
|
||||
#endif /* __UIP_ARCH_H */
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* net/uip/uip-icmp.h
|
||||
* Header file for the uIP ICMP stack.
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* This logic was leveraged from uIP which also has a BSD-style license:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue