net: Fix alignment error with net_ipaddr_copy()

As struct sockaddr have now alignment of 4 bytes, net_ipaddr_copy()
gives the following error if used for sockaddr:

  error: alignment 1 of ‘struct <anonymous>’ is less than 4
  [-Werror=packed-not-aligned]

Just use memcpy() instead, net_ipaddr_copy() was intended to use with IP
addresses, not socket related structs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2025-07-02 13:13:42 +02:00 committed by Daniel DeGrasse
parent 48d1a01b2d
commit 62a5260e01
2 changed files with 3 additions and 3 deletions

View File

@ -154,7 +154,7 @@ static int smp_udp_ud_copy(struct net_buf *dst, const struct net_buf *src)
struct sockaddr *src_ud = net_buf_user_data(src);
struct sockaddr *dst_ud = net_buf_user_data(dst);
net_ipaddr_copy(dst_ud, src_ud);
memcpy(dst_ud, src_ud, sizeof(struct sockaddr));
return MGMT_ERR_EOK;
}
@ -249,7 +249,7 @@ static void smp_udp_receive_thread(void *p1, void *p2, void *p3)
}
net_buf_add_mem(nb, conf->recv_buffer, len);
ud = net_buf_user_data(nb);
net_ipaddr_copy(ud, &addr);
memcpy(ud, &addr, sizeof(addr));
smp_rx_req(&conf->smp_transport, nb);
} else if (len < 0) {

View File

@ -1962,7 +1962,7 @@ void coap_observer_init(struct coap_observer *observer,
{
observer->tkl = coap_header_get_token(request, observer->token);
net_ipaddr_copy(&observer->addr, addr);
memcpy(&observer->addr, addr, sizeof(*addr));
}
static inline void coap_observer_raise_event(struct coap_resource *resource,