fix
authorChristian Grothoff <christian@grothoff.org>
Sat, 21 Aug 2010 07:30:50 +0000 (07:30 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 21 Aug 2010 07:30:50 +0000 (07:30 +0000)
src/transport/gnunet-nat-client-windows.c
src/transport/gnunet-nat-client.c

index febcfc7172e7d561de204595df47934bb423b290..aae487b764c5428961b8180a847fbfca2a609ac1 100644 (file)
@@ -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");
index 2fc2a51a099138e4f645f55e8444c385676cbb56..d38f3bcdfbfd7d5ab589b0ee517fd3ea691e737a 100644 (file)
@@ -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");