diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-08-21 14:20:00 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-08-21 11:59:56 +0200 |
commit | ceea52ca9310054cdc822552c4066073bd513ac4 (patch) | |
tree | d61c89f177f61b4347393c243e5269bb63f859df | |
parent | 905ecd2b0b8a6ab68b66017ec47e094253233e74 (diff) | |
download | passt-ceea52ca9310054cdc822552c4066073bd513ac4.tar passt-ceea52ca9310054cdc822552c4066073bd513ac4.tar.gz passt-ceea52ca9310054cdc822552c4066073bd513ac4.tar.bz2 passt-ceea52ca9310054cdc822552c4066073bd513ac4.tar.lz passt-ceea52ca9310054cdc822552c4066073bd513ac4.tar.xz passt-ceea52ca9310054cdc822552c4066073bd513ac4.tar.zst passt-ceea52ca9310054cdc822552c4066073bd513ac4.zip |
treewide: Use struct assignment instead of memcpy() for IP addresses
We rely on C11 already, so we can use clearer and more type-checkable
struct assignment instead of mempcy() for copying IP addresses around.
This exposes some "pointer could be const" warnings from cppcheck, so
address those too.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | conf.c | 12 | ||||
-rw-r--r-- | dhcpv6.c | 10 |
2 files changed, 12 insertions, 10 deletions
@@ -389,14 +389,14 @@ static void add_dns6(struct ctx *c, /* Guest or container can only access local addresses via redirect */ if (IN6_IS_ADDR_LOOPBACK(addr)) { if (!c->no_map_gw) { - memcpy(*conf, &c->ip6.gw, sizeof(**conf)); + **conf = c->ip6.gw; (*conf)++; if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_match)) - memcpy(&c->ip6.dns_match, addr, sizeof(*addr)); + c->ip6.dns_match = *addr; } } else { - memcpy(*conf, addr, sizeof(**conf)); + **conf = *addr; (*conf)++; } @@ -632,7 +632,7 @@ static unsigned int conf_ip4(unsigned int ifi, ip4->prefix_len = 32; } - memcpy(&ip4->addr_seen, &ip4->addr, sizeof(ip4->addr_seen)); + ip4->addr_seen = ip4->addr; if (MAC_IS_ZERO(mac)) { int rc = nl_link_get_mac(nl_sock, ifi, mac); @@ -693,8 +693,8 @@ static unsigned int conf_ip6(unsigned int ifi, return 0; } - memcpy(&ip6->addr_seen, &ip6->addr, sizeof(ip6->addr)); - memcpy(&ip6->addr_ll_seen, &ip6->addr_ll, sizeof(ip6->addr_ll)); + ip6->addr_seen = ip6->addr; + ip6->addr_ll_seen = ip6->addr_ll; if (MAC_IS_ZERO(mac)) { rc = nl_link_get_mac(nl_sock, ifi, mac); @@ -298,7 +298,8 @@ static struct opt_hdr *dhcpv6_ia_notonlink(const struct pool *p, { char buf[INET6_ADDRSTRLEN]; struct in6_addr req_addr; - struct opt_hdr *ia, *h; + const struct opt_hdr *h; + struct opt_hdr *ia; size_t offset; int ia_type; @@ -312,12 +313,13 @@ ia_ta: offset += sizeof(struct opt_ia_na); while ((h = dhcpv6_opt(p, &offset, OPT_IAAADR))) { - struct opt_ia_addr *opt_addr = (struct opt_ia_addr *)h; + const struct opt_ia_addr *opt_addr; if (ntohs(h->l) != OPT_VSIZE(ia_addr)) return NULL; - memcpy(&req_addr, &opt_addr->addr, sizeof(req_addr)); + opt_addr = (const struct opt_ia_addr *)h; + req_addr = opt_addr->addr; if (!IN6_ARE_ADDR_EQUAL(la, &req_addr)) { info("DHCPv6: requested address %s not on link", inet_ntop(AF_INET6, &req_addr, @@ -363,7 +365,7 @@ static size_t dhcpv6_dns_fill(const struct ctx *c, char *buf, int offset) srv->hdr.l = 0; } - memcpy(&srv->addr[i], &c->ip6.dns[i], sizeof(srv->addr[i])); + srv->addr[i] = c->ip6.dns[i]; srv->hdr.l += sizeof(srv->addr[i]); offset += sizeof(srv->addr[i]); } |