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>
This commit is contained in:
parent
905ecd2b0b
commit
ceea52ca93
2 changed files with 12 additions and 10 deletions
12
conf.c
12
conf.c
|
@ -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);
|
||||
|
|
10
dhcpv6.c
10
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]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue