Skip to content

Commit 62a5260

Browse files
rlubosdanieldegrasse
authored andcommitted
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>
1 parent 48d1a01 commit 62a5260

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

subsys/mgmt/mcumgr/transport/src/smp_udp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int smp_udp_ud_copy(struct net_buf *dst, const struct net_buf *src)
154154
struct sockaddr *src_ud = net_buf_user_data(src);
155155
struct sockaddr *dst_ud = net_buf_user_data(dst);
156156

157-
net_ipaddr_copy(dst_ud, src_ud);
157+
memcpy(dst_ud, src_ud, sizeof(struct sockaddr));
158158

159159
return MGMT_ERR_EOK;
160160
}
@@ -249,7 +249,7 @@ static void smp_udp_receive_thread(void *p1, void *p2, void *p3)
249249
}
250250
net_buf_add_mem(nb, conf->recv_buffer, len);
251251
ud = net_buf_user_data(nb);
252-
net_ipaddr_copy(ud, &addr);
252+
memcpy(ud, &addr, sizeof(addr));
253253

254254
smp_rx_req(&conf->smp_transport, nb);
255255
} else if (len < 0) {

subsys/net/lib/coap/coap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ void coap_observer_init(struct coap_observer *observer,
19621962
{
19631963
observer->tkl = coap_header_get_token(request, observer->token);
19641964

1965-
net_ipaddr_copy(&observer->addr, addr);
1965+
memcpy(&observer->addr, addr, sizeof(*addr));
19661966
}
19671967

19681968
static inline void coap_observer_raise_event(struct coap_resource *resource,

0 commit comments

Comments
 (0)