From 0465310093c39138a7b894e15b40a819ce768ae4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 21 Aug 2010 07:30:50 +0000 Subject: [PATCH] fix --- src/transport/gnunet-nat-client-windows.c | 15 ++++++++------- src/transport/gnunet-nat-client.c | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/transport/gnunet-nat-client-windows.c b/src/transport/gnunet-nat-client-windows.c index febcfc717..aae487b76 100644 --- a/src/transport/gnunet-nat-client-windows.c +++ b/src/transport/gnunet-nat-client-windows.c @@ -300,18 +300,19 @@ send_icmp_udp (const struct in_addr *my_ip, memcpy(&packet[off], &udp_pkt, sizeof(udp_pkt)); off += sizeof(udp_pkt); - /* set ICMP checksum */ - icmp_pkt.checksum = htons(calc_checksum((uint16_t*)&packet[sizeof(ip_pkt)], - sizeof (icmp_pkt) + sizeof(ip_pkt) + sizeof(udp_pkt))); - memcpy (&packet[sizeof(ip_pkt)], &icmp_pkt, sizeof (icmp_pkt)); - + /* no go back to calculate ICMP packet checksum */ + off = sizeof (ip_pkt); + icmp_pkt.checksum = htons(calc_checksum((uint16_t*)&packet[off], + sizeof (icmp_pkt) + sizeof(ip_pkt) + sizeof(udp_pkt))); + memcpy (&packet[off], &icmp_pkt, sizeof (icmp_pkt)); + memset (&dst, 0, sizeof (dst)); dst.sin_family = AF_INET; dst.sin_addr = *other; err = sendto(rawsock, packet, - off, 0, + sizeof (packet), 0, (struct sockaddr*)&dst, sizeof(dst)); @@ -320,7 +321,7 @@ send_icmp_udp (const struct in_addr *my_ip, fprintf(stderr, "sendto failed: %s\n", strerror(errno)); } - else if (err != off) + else if (err != sizeof (packet)) { fprintf(stderr, "Error: partial send of ICMP message\n"); diff --git a/src/transport/gnunet-nat-client.c b/src/transport/gnunet-nat-client.c index 2fc2a51a0..d38f3bcdf 100644 --- a/src/transport/gnunet-nat-client.c +++ b/src/transport/gnunet-nat-client.c @@ -324,6 +324,7 @@ send_icmp (const struct in_addr *my_ip, int err; /* ip header: send to (known) ip address */ + off = 0; ip_pkt.vers_ihl = 0x45; ip_pkt.tos = 0; ip_pkt.pkt_len = sizeof (packet); /* huh? */ @@ -335,7 +336,7 @@ send_icmp (const struct in_addr *my_ip, ip_pkt.src_ip = my_ip->s_addr; ip_pkt.dst_ip = other->s_addr; ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt, sizeof (struct ip_packet))); - memcpy (packet, &ip_pkt, sizeof (struct ip_packet)); + memcpy (&packet[off], &ip_pkt, sizeof (struct ip_packet)); off = sizeof (ip_pkt); /* icmp reply: time exceeded */ @@ -391,7 +392,7 @@ send_icmp (const struct in_addr *my_ip, dst.sin_addr = *other; err = sendto(rawsock, packet, - off, 0, + sizeof (packet), 0, (struct sockaddr*)&dst, sizeof(struct sockaddr_in)); if (err < 0) @@ -399,7 +400,7 @@ send_icmp (const struct in_addr *my_ip, fprintf(stderr, "sendto failed: %s\n", strerror(errno)); } - else if (err != off) + else if (err != sizeof (packet)) { fprintf(stderr, "Error: partial send of ICMP message\n"); -- 2.25.1