tests/net: dhcpv6: Avoid directly accessing address of unaligned struct

Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2025-07-01 15:47:35 +02:00 committed by Daniel DeGrasse
parent a1d916edd0
commit 35a10937d7

View File

@ -109,8 +109,10 @@ static void generate_fake_server_duid(void)
memset(serverid, 0, sizeof(*serverid));
UNALIGNED_PUT(htons(DHCPV6_DUID_TYPE_LL), &serverid->duid.type);
UNALIGNED_PUT(htons(DHCPV6_HARDWARE_ETHERNET_TYPE), &duid_ll->hw_type);
UNALIGNED_PUT(htons(DHCPV6_DUID_TYPE_LL),
UNALIGNED_MEMBER_ADDR(serverid, duid.type));
UNALIGNED_PUT(htons(DHCPV6_HARDWARE_ETHERNET_TYPE),
UNALIGNED_MEMBER_ADDR(duid_ll, hw_type));
memcpy(duid_ll->ll_addr, fake_mac, sizeof(fake_mac));
serverid->length = DHCPV6_DUID_LL_HEADER_SIZE + sizeof(fake_mac);