aboutsummaryrefslogtreecommitdiff
path: root/src/nat
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-13 19:55:46 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-13 19:55:46 +0200
commitfa2978883e1585b1eeff3a22b7a9b4f174a45ca3 (patch)
tree52800dd5062534729be80227608def6f6c0c45ac /src/nat
parent2bb2faa207e4015609100a1aca38af344c65596f (diff)
downloadgnunet-fa2978883e1585b1eeff3a22b7a9b4f174a45ca3.tar.gz
gnunet-fa2978883e1585b1eeff3a22b7a9b4f174a45ca3.zip
get rid of plain memcpy calls
Diffstat (limited to 'src/nat')
-rw-r--r--src/nat/gnunet-helper-nat-client.c43
-rw-r--r--src/nat/gnunet-helper-nat-server.c32
-rw-r--r--src/nat/gnunet-service-nat.c8
3 files changed, 58 insertions, 25 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));
diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c
index ef8e97482..f35649152 100644
--- a/src/nat/gnunet-helper-nat-server.c
+++ b/src/nat/gnunet-helper-nat-server.c
@@ -266,9 +266,9 @@ send_icmp_echo (const struct in_addr *my_ip)
266 ip_pkt.checksum = 266 ip_pkt.checksum =
267 htons (calc_checksum ((uint16_t *) & ip_pkt, 267 htons (calc_checksum ((uint16_t *) & ip_pkt,
268 sizeof (struct ip_header))); 268 sizeof (struct ip_header)));
269 memcpy (&packet[off], 269 GNUNET_memcpy (&packet[off],
270 &ip_pkt, 270 &ip_pkt,
271 sizeof (struct ip_header)); 271 sizeof (struct ip_header));
272 off += sizeof (struct ip_header); 272 off += sizeof (struct ip_header);
273 273
274 icmp_echo.type = ICMP_ECHO; 274 icmp_echo.type = ICMP_ECHO;
@@ -279,9 +279,9 @@ send_icmp_echo (const struct in_addr *my_ip)
279 htons (calc_checksum 279 htons (calc_checksum
280 ((uint16_t *) & icmp_echo, 280 ((uint16_t *) & icmp_echo,
281 sizeof (struct icmp_echo_header))); 281 sizeof (struct icmp_echo_header)));
282 memcpy (&packet[off], 282 GNUNET_memcpy (&packet[off],
283 &icmp_echo, 283 &icmp_echo,
284 sizeof (struct icmp_echo_header)); 284 sizeof (struct icmp_echo_header));
285 off += sizeof (struct icmp_echo_header); 285 off += sizeof (struct icmp_echo_header);
286 286
287 memset (&dst, 0, sizeof (dst)); 287 memset (&dst, 0, sizeof (dst));
@@ -388,9 +388,13 @@ process_icmp_response ()
388 return; 388 return;
389 } 389 }
390 off = 0; 390 off = 0;
391 memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); 391 GNUNET_memcpy (&ip_pkt,
392 &buf[off],
393 sizeof (struct ip_header));
392 off += sizeof (struct ip_header); 394 off += sizeof (struct ip_header);
393 memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header)); 395 GNUNET_memcpy (&icmp_ttl,
396 &buf[off],
397 sizeof (struct icmp_ttl_exceeded_header));
394 off += sizeof (struct icmp_ttl_exceeded_header); 398 off += sizeof (struct icmp_ttl_exceeded_header);
395 if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code)) 399 if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
396 { 400 {
@@ -401,7 +405,9 @@ process_icmp_response ()
401 source_ip.s_addr = ip_pkt.src_ip; 405 source_ip.s_addr = ip_pkt.src_ip;
402 406
403 /* skip 2nd IP header */ 407 /* skip 2nd IP header */
404 memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); 408 GNUNET_memcpy (&ip_pkt,
409 &buf[off],
410 sizeof (struct ip_header));
405 off += sizeof (struct ip_header); 411 off += sizeof (struct ip_header);
406 412
407 switch (ip_pkt.proto) 413 switch (ip_pkt.proto)
@@ -416,7 +422,9 @@ process_icmp_response ()
416 return; 422 return;
417 } 423 }
418 /* grab ICMP ECHO content */ 424 /* grab ICMP ECHO content */
419 memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header)); 425 GNUNET_memcpy (&icmp_echo,
426 &buf[off],
427 sizeof (struct icmp_echo_header));
420 port = (uint16_t) ntohl (icmp_echo.reserved); 428 port = (uint16_t) ntohl (icmp_echo.reserved);
421 break; 429 break;
422 case IPPROTO_UDP: 430 case IPPROTO_UDP:
@@ -428,7 +436,9 @@ process_icmp_response ()
428 return; 436 return;
429 } 437 }
430 /* grab UDP content */ 438 /* grab UDP content */
431 memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header)); 439 GNUNET_memcpy (&udp_pkt,
440 &buf[off],
441 sizeof (struct udp_header));
432 port = ntohs (udp_pkt.length); 442 port = ntohs (udp_pkt.length);
433 break; 443 break;
434 default: 444 default:
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index 0695c7ac7..21089890d 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -1234,8 +1234,12 @@ process_external_ip (void *cls,
1234 ch->hole_external); 1234 ch->hole_external);
1235 1235
1236 /* build sockaddr storage with port number */ 1236 /* build sockaddr storage with port number */
1237 memset (&ss, 0, sizeof (ss)); 1237 memset (&ss,
1238 memcpy (&ss, addr, addrlen); 1238 0,
1239 sizeof (ss));
1240 GNUNET_memcpy (&ss,
1241 addr,
1242 addrlen);
1239 switch (addr->sa_family) 1243 switch (addr->sa_family)
1240 { 1244 {
1241 case AF_INET: 1245 case AF_INET: