aboutgitcodebugslistschat
path: root/dhcpv6.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-08-21 14:20:00 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-08-21 11:59:56 +0200
commitceea52ca9310054cdc822552c4066073bd513ac4 (patch)
treed61c89f177f61b4347393c243e5269bb63f859df /dhcpv6.c
parent905ecd2b0b8a6ab68b66017ec47e094253233e74 (diff)
downloadpasst-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>
Diffstat (limited to 'dhcpv6.c')
-rw-r--r--dhcpv6.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/dhcpv6.c b/dhcpv6.c
index bbed41d..1c595fd 100644
--- a/dhcpv6.c
+++ b/dhcpv6.c
@@ -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]);
}