aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-nat-client-windows.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-08-18 16:10:12 +0000
committerNathan S. Evans <evans@in.tum.de>2010-08-18 16:10:12 +0000
commit73db05960240862fa2035948bd51eb10a450477d (patch)
treededab4caa3a969c5b443df9e55d949ea25eb2280 /src/transport/gnunet-nat-client-windows.c
parent0cfd4f19380f5474caa4f3ea9e1195d3cd14a318 (diff)
downloadgnunet-73db05960240862fa2035948bd51eb10a450477d.tar.gz
gnunet-73db05960240862fa2035948bd51eb10a450477d.zip
windoze suckssss
Diffstat (limited to 'src/transport/gnunet-nat-client-windows.c')
-rw-r--r--src/transport/gnunet-nat-client-windows.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/transport/gnunet-nat-client-windows.c b/src/transport/gnunet-nat-client-windows.c
index 02c5d1c79..a9c38ddb2 100644
--- a/src/transport/gnunet-nat-client-windows.c
+++ b/src/transport/gnunet-nat-client-windows.c
@@ -180,6 +180,61 @@ make_echo (const struct in_addr *src_ip,
180 sizeof (struct icmp_echo_packet))); 180 sizeof (struct icmp_echo_packet)));
181} 181}
182 182
183/**
184 * Send an ICMP message to the dummy IP.
185 *
186 * @param my_ip source address (our ip address)
187 */
188static void
189send_icmp_echo (const struct in_addr *my_ip)
190{
191 struct icmp_packet icmp_echo;
192 struct sockaddr_in dst;
193 size_t off;
194 int err;
195 struct ip_packet ip_pkt;
196 struct icmp_packet icmp_pkt;
197 char packet[sizeof (ip_pkt) + sizeof (icmp_pkt)];
198
199 off = 0;
200 memset(&ip_pkt, 0, sizeof(ip_pkt));
201 ip_pkt.vers_ihl = 0x45;
202 ip_pkt.tos = 0;
203 ip_pkt.pkt_len = sizeof (packet);
204 ip_pkt.id = 1;
205 ip_pkt.flags_frag_offset = 0;
206 ip_pkt.ttl = IPDEFTTL;
207 ip_pkt.proto = IPPROTO_ICMP;
208 ip_pkt.checksum = 0;
209 ip_pkt.src_ip = my_ip->s_addr;
210 ip_pkt.dst_ip = dummy.s_addr;
211 ip_pkt.checksum = htons(calc_checksum((uint16_t*)&ip_pkt, sizeof (ip_pkt)));
212 memcpy (packet, &ip_pkt, sizeof (ip_pkt));
213 off += sizeof (ip_pkt);
214 make_echo (my_ip, &icmp_echo);
215 memcpy (&packet[off], &icmp_echo, sizeof (icmp_echo));
216 off += sizeof (icmp_echo);
217
218 memset (&dst, 0, sizeof (dst));
219 dst.sin_family = AF_INET;
220 dst.sin_addr = dummy;
221 err = sendto(rawsock,
222 packet, off, 0,
223 (struct sockaddr*)&dst,
224 sizeof(dst));
225 if (err < 0)
226 {
227#if VERBOSE
228 fprintf(stderr,
229 "sendto failed: %s\n", strerror(errno));
230#endif
231 }
232 else if (err != off)
233 {
234 fprintf(stderr,
235 "Error: partial send of ICMP message\n");
236 }
237}
183 238
184/** 239/**
185 * Send an ICMP message to the target. 240 * Send an ICMP message to the target.
@@ -454,6 +509,7 @@ main (int argc, char *const *argv)
454 strerror (errno)); 509 strerror (errno));
455 abort (); 510 abort ();
456 } 511 }
512 send_icmp_echo(&target);
457 fprintf(stderr, "Sending icmp message.\n"); 513 fprintf(stderr, "Sending icmp message.\n");
458 send_icmp (&external, 514 send_icmp (&external,
459 &target); 515 &target);