diff options
Diffstat (limited to 'src/nat/gnunet-helper-nat-client.c')
-rw-r--r-- | src/nat/gnunet-helper-nat-client.c | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/nat/gnunet-helper-nat-client.c b/src/nat/gnunet-helper-nat-client.c index d9129afb0..9768dd856 100644 --- a/src/nat/gnunet-helper-nat-client.c +++ b/src/nat/gnunet-helper-nat-client.c | |||
@@ -251,14 +251,18 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
251 | ip_pkt.dst_ip = other->s_addr; | 251 | ip_pkt.dst_ip = other->s_addr; |
252 | ip_pkt.checksum = | 252 | ip_pkt.checksum = |
253 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 253 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
254 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 254 | GNUNET_memcpy (&packet[off], |
255 | &ip_pkt, | ||
256 | sizeof (struct ip_header)); | ||
255 | off += sizeof (struct ip_header); | 257 | off += sizeof (struct ip_header); |
256 | 258 | ||
257 | icmp_pkt.type = ICMP_TIME_EXCEEDED; | 259 | icmp_pkt.type = ICMP_TIME_EXCEEDED; |
258 | icmp_pkt.code = 0; | 260 | icmp_pkt.code = 0; |
259 | icmp_pkt.checksum = 0; | 261 | icmp_pkt.checksum = 0; |
260 | icmp_pkt.unused = 0; | 262 | icmp_pkt.unused = 0; |
261 | memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header)); | 263 | GNUNET_memcpy (&packet[off], |
264 | &icmp_pkt, | ||
265 | sizeof (struct icmp_ttl_exceeded_header)); | ||
262 | off += sizeof (struct icmp_ttl_exceeded_header); | 266 | off += sizeof (struct icmp_ttl_exceeded_header); |
263 | 267 | ||
264 | /* ip header of the presumably 'lost' udp packet */ | 268 | /* ip header of the presumably 'lost' udp packet */ |
@@ -275,7 +279,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
275 | ip_pkt.dst_ip = dummy.s_addr; | 279 | ip_pkt.dst_ip = dummy.s_addr; |
276 | ip_pkt.checksum = | 280 | ip_pkt.checksum = |
277 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 281 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
278 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 282 | GNUNET_memcpy (&packet[off], |
283 | &ip_pkt, | ||
284 | sizeof (struct ip_header)); | ||
279 | off += sizeof (struct ip_header); | 285 | off += sizeof (struct ip_header); |
280 | 286 | ||
281 | /* build UDP header */ | 287 | /* build UDP header */ |
@@ -283,7 +289,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
283 | udp_pkt.dst_port = htons (NAT_TRAV_PORT); | 289 | udp_pkt.dst_port = htons (NAT_TRAV_PORT); |
284 | udp_pkt.length = htons (port); | 290 | udp_pkt.length = htons (port); |
285 | udp_pkt.crc = 0; | 291 | udp_pkt.crc = 0; |
286 | memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header)); | 292 | GNUNET_memcpy (&packet[off], |
293 | &udp_pkt, | ||
294 | sizeof (struct udp_header)); | ||
287 | off += sizeof (struct udp_header); | 295 | off += sizeof (struct udp_header); |
288 | 296 | ||
289 | /* set ICMP checksum */ | 297 | /* set ICMP checksum */ |
@@ -292,8 +300,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other) | |||
292 | ((uint16_t *) & packet[sizeof (struct ip_header)], | 300 | ((uint16_t *) & packet[sizeof (struct ip_header)], |
293 | sizeof (struct icmp_ttl_exceeded_header) + | 301 | sizeof (struct icmp_ttl_exceeded_header) + |
294 | sizeof (struct ip_header) + sizeof (struct udp_header))); | 302 | sizeof (struct ip_header) + sizeof (struct udp_header))); |
295 | memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt, | 303 | GNUNET_memcpy (&packet[sizeof (struct ip_header)], |
296 | sizeof (struct icmp_ttl_exceeded_header)); | 304 | &icmp_pkt, |
305 | sizeof (struct icmp_ttl_exceeded_header)); | ||
297 | 306 | ||
298 | memset (&dst, 0, sizeof (dst)); | 307 | memset (&dst, 0, sizeof (dst)); |
299 | dst.sin_family = AF_INET; | 308 | dst.sin_family = AF_INET; |
@@ -352,7 +361,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
352 | ip_pkt.dst_ip = other->s_addr; | 361 | ip_pkt.dst_ip = other->s_addr; |
353 | ip_pkt.checksum = | 362 | ip_pkt.checksum = |
354 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 363 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
355 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 364 | GNUNET_memcpy (&packet[off], |
365 | &ip_pkt, | ||
366 | sizeof (struct ip_header)); | ||
356 | off = sizeof (ip_pkt); | 367 | off = sizeof (ip_pkt); |
357 | 368 | ||
358 | /* icmp reply: time exceeded */ | 369 | /* icmp reply: time exceeded */ |
@@ -360,7 +371,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
360 | icmp_ttl.code = 0; | 371 | icmp_ttl.code = 0; |
361 | icmp_ttl.checksum = 0; | 372 | icmp_ttl.checksum = 0; |
362 | icmp_ttl.unused = 0; | 373 | icmp_ttl.unused = 0; |
363 | memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); | 374 | GNUNET_memcpy (&packet[off], |
375 | &icmp_ttl, | ||
376 | sizeof (struct icmp_ttl_exceeded_header)); | ||
364 | off += sizeof (struct icmp_ttl_exceeded_header); | 377 | off += sizeof (struct icmp_ttl_exceeded_header); |
365 | 378 | ||
366 | /* ip header of the presumably 'lost' udp packet */ | 379 | /* ip header of the presumably 'lost' udp packet */ |
@@ -377,7 +390,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
377 | ip_pkt.checksum = 0; | 390 | ip_pkt.checksum = 0; |
378 | ip_pkt.checksum = | 391 | ip_pkt.checksum = |
379 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 392 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); |
380 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 393 | GNUNET_memcpy (&packet[off], |
394 | &ip_pkt, | ||
395 | sizeof (struct ip_header)); | ||
381 | off += sizeof (struct ip_header); | 396 | off += sizeof (struct ip_header); |
382 | 397 | ||
383 | icmp_echo.type = ICMP_ECHO; | 398 | icmp_echo.type = ICMP_ECHO; |
@@ -386,8 +401,10 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
386 | icmp_echo.checksum = 0; | 401 | icmp_echo.checksum = 0; |
387 | icmp_echo.checksum = | 402 | icmp_echo.checksum = |
388 | htons (calc_checksum | 403 | htons (calc_checksum |
389 | ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); | 404 | ((uint16_t *) &icmp_echo, sizeof (struct icmp_echo_header))); |
390 | memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); | 405 | GNUNET_memcpy (&packet[off], |
406 | &icmp_echo, | ||
407 | sizeof (struct icmp_echo_header)); | ||
391 | 408 | ||
392 | /* no go back to calculate ICMP packet checksum */ | 409 | /* no go back to calculate ICMP packet checksum */ |
393 | off = sizeof (struct ip_header); | 410 | off = sizeof (struct ip_header); |
@@ -396,7 +413,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other) | |||
396 | ((uint16_t *) & packet[off], | 413 | ((uint16_t *) & packet[off], |
397 | sizeof (struct icmp_ttl_exceeded_header) + | 414 | sizeof (struct icmp_ttl_exceeded_header) + |
398 | sizeof (struct ip_header) + sizeof (struct icmp_echo_header))); | 415 | sizeof (struct ip_header) + sizeof (struct icmp_echo_header))); |
399 | memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); | 416 | GNUNET_memcpy (&packet[off], |
417 | &icmp_ttl, | ||
418 | sizeof (struct icmp_ttl_exceeded_header)); | ||
400 | 419 | ||
401 | /* prepare for transmission */ | 420 | /* prepare for transmission */ |
402 | memset (&dst, 0, sizeof (dst)); | 421 | memset (&dst, 0, sizeof (dst)); |