X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Froute.c;h=06dffc97324a20cc95ee449ba67840e00754f32e;hp=00aa486368b9e1327483f390212a6ecb6323f257;hb=8285827da127e38728b60b5c5484e5cdabff2f21;hpb=7d21a8d1c7fd8909fe02385dbb4717c074db4648 diff --git a/src/route.c b/src/route.c index 00aa4863..06dffc97 100644 --- a/src/route.c +++ b/src/route.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: route.c,v 1.1.2.47 2003/03/29 21:51:21 guus Exp $ + $Id: route.c,v 1.1.2.49 2003/03/29 22:11:22 guus Exp $ */ #include "config.h" @@ -76,10 +76,13 @@ uint16_t inet_checksum(void *data, int len, uint16_t prevsum) uint16_t *p = data; uint32_t checksum = prevsum ^ 0xFFFF; - len /= 2; - - while(len--) + while(len >= 2) { checksum += *p++; + len -= 2; + } + + if(len) + checksum += *(unsigned char *)p; while(checksum >> 16) checksum = (checksum & 0xFFFF) + (checksum >> 16); @@ -295,8 +298,8 @@ void route_ipv6_unreachable(vpn_packet_t *packet, uint8_t code) /* Remember original source and destination */ - memcpy(&pseudo.ip6_src, &hdr->ip6_src, 16); - memcpy(&pseudo.ip6_dst, &hdr->ip6_dst, 16); + memcpy(&pseudo.ip6_src, &hdr->ip6_dst, 16); + memcpy(&pseudo.ip6_dst, &hdr->ip6_src, 16); pseudo.length = ntohs(hdr->ip6_plen) + sizeof(*hdr); if(pseudo.length >= IP_MSS - sizeof(*hdr) - sizeof(*icmp)) @@ -312,8 +315,8 @@ void route_ipv6_unreachable(vpn_packet_t *packet, uint8_t code) hdr->ip6_plen = htons(sizeof(*icmp) + pseudo.length); hdr->ip6_nxt = IPPROTO_ICMPV6; hdr->ip6_hlim = 255; - memcpy(&hdr->ip6_dst, &pseudo.ip6_src, 16); - memcpy(&hdr->ip6_src, &pseudo.ip6_dst, 16); + memcpy(&hdr->ip6_dst, &pseudo.ip6_dst, 16); + memcpy(&hdr->ip6_src, &pseudo.ip6_src, 16); /* Fill in ICMP header */ @@ -323,8 +326,6 @@ void route_ipv6_unreachable(vpn_packet_t *packet, uint8_t code) /* Create pseudo header */ - memcpy(&pseudo.ip6_src, &hdr->ip6_src, 16); - memcpy(&pseudo.ip6_dst, &hdr->ip6_dst, 16); pseudo.length = htonl(sizeof(*icmp) + pseudo.length); pseudo.next = htonl(IPPROTO_ICMPV6);