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)
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 d9129afb08..9768dd8563 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)
ip_pkt.dst_ip = other->s_addr;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_pkt.type = ICMP_TIME_EXCEEDED;
icmp_pkt.code = 0;
icmp_pkt.checksum = 0;
icmp_pkt.unused = 0;
- memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_pkt,
+ sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
/* 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)
ip_pkt.dst_ip = dummy.s_addr;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
/* build UDP header */
@@ -283,7 +289,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
udp_pkt.dst_port = htons (NAT_TRAV_PORT);
udp_pkt.length = htons (port);
udp_pkt.crc = 0;
- memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header));
+ GNUNET_memcpy (&packet[off],
+ &udp_pkt,
+ sizeof (struct udp_header));
off += sizeof (struct udp_header);
/* set ICMP checksum */
@@ -292,8 +300,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
((uint16_t *) & packet[sizeof (struct ip_header)],
sizeof (struct icmp_ttl_exceeded_header) +
sizeof (struct ip_header) + sizeof (struct udp_header)));
- memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt,
- sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[sizeof (struct ip_header)],
+ &icmp_pkt,
+ sizeof (struct icmp_ttl_exceeded_header));
memset (&dst, 0, sizeof (dst));
dst.sin_family = AF_INET;
@@ -352,7 +361,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
ip_pkt.dst_ip = other->s_addr;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off = sizeof (ip_pkt);
/* icmp reply: time exceeded */
@@ -360,7 +371,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
icmp_ttl.code = 0;
icmp_ttl.checksum = 0;
icmp_ttl.unused = 0;
- memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_ttl,
+ sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
/* 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)
ip_pkt.checksum = 0;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
@@ -386,8 +401,10 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
icmp_echo.checksum = 0;
icmp_echo.checksum =
htons (calc_checksum
- ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
- memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
+ ((uint16_t *) &icmp_echo, sizeof (struct icmp_echo_header)));
+ GNUNET_memcpy (&packet[off],
+ &icmp_echo,
+ sizeof (struct icmp_echo_header));
/* no go back to calculate ICMP packet checksum */
off = sizeof (struct ip_header);
@@ -396,7 +413,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
((uint16_t *) & packet[off],
sizeof (struct icmp_ttl_exceeded_header) +
sizeof (struct ip_header) + sizeof (struct icmp_echo_header)));
- memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_ttl,
+ sizeof (struct icmp_ttl_exceeded_header));
/* prepare for transmission */
memset (&dst, 0, sizeof (dst));
diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c
index ef8e974827..f356491526 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)
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt,
sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
@@ -279,9 +279,9 @@ send_icmp_echo (const struct in_addr *my_ip)
htons (calc_checksum
((uint16_t *) & icmp_echo,
sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_echo,
- sizeof (struct icmp_echo_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_echo,
+ sizeof (struct icmp_echo_header));
off += sizeof (struct icmp_echo_header);
memset (&dst, 0, sizeof (dst));
@@ -388,9 +388,13 @@ process_icmp_response ()
return;
}
off = 0;
- memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
+ GNUNET_memcpy (&ip_pkt,
+ &buf[off],
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
- memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&icmp_ttl,
+ &buf[off],
+ sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
{
@@ -401,7 +405,9 @@ process_icmp_response ()
source_ip.s_addr = ip_pkt.src_ip;
/* skip 2nd IP header */
- memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
+ GNUNET_memcpy (&ip_pkt,
+ &buf[off],
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
switch (ip_pkt.proto)
@@ -416,7 +422,9 @@ process_icmp_response ()
return;
}
/* grab ICMP ECHO content */
- memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header));
+ GNUNET_memcpy (&icmp_echo,
+ &buf[off],
+ sizeof (struct icmp_echo_header));
port = (uint16_t) ntohl (icmp_echo.reserved);
break;
case IPPROTO_UDP:
@@ -428,7 +436,9 @@ process_icmp_response ()
return;
}
/* grab UDP content */
- memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header));
+ GNUNET_memcpy (&udp_pkt,
+ &buf[off],
+ sizeof (struct udp_header));
port = ntohs (udp_pkt.length);
break;
default:
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index 0695c7ac70..21089890de 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -1234,8 +1234,12 @@ process_external_ip (void *cls,
ch->hole_external);
/* build sockaddr storage with port number */
- memset (&ss, 0, sizeof (ss));
- memcpy (&ss, addr, addrlen);
+ memset (&ss,
+ 0,
+ sizeof (ss));
+ GNUNET_memcpy (&ss,
+ addr,
+ addrlen);
switch (addr->sa_family)
{
case AF_INET: