diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-02-15 23:43:15 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-02-16 16:23:54 +0900 |
commit | c9333c236ff6a6100e7c9eefb72d9527637dc76a (patch) | |
tree | 74e7e97ce3464e8766242231f9f212f63fcc2109 /src/libsystemd-network/dhcp-identifier.c | |
parent | fc62d1c54f84a9b203c76b58bb63d4e1e37406e8 (diff) | |
download | systemd-c9333c236ff6a6100e7c9eefb72d9527637dc76a.tar.gz |
dhcp-identifier: use offsetof()
Also use appropriate place to store UUID.
Diffstat (limited to 'src/libsystemd-network/dhcp-identifier.c')
-rw-r--r-- | src/libsystemd-network/dhcp-identifier.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libsystemd-network/dhcp-identifier.c b/src/libsystemd-network/dhcp-identifier.c index ce59216c1b..d2b190244f 100644 --- a/src/libsystemd-network/dhcp-identifier.c +++ b/src/libsystemd-network/dhcp-identifier.c @@ -91,7 +91,7 @@ static int dhcp_identifier_set_duid_llt(const uint8_t *addr, size_t addr_len, ui unaligned_write_be32(&ret_duid->llt.time, time_from_2000y); memcpy(ret_duid->llt.haddr, addr, addr_len); - *ret_len = sizeof(ret_duid->type) + sizeof(ret_duid->llt.htype) + sizeof(ret_duid->llt.time) + addr_len; + *ret_len = offsetof(struct duid, llt.haddr) + addr_len; return 0; } @@ -115,7 +115,7 @@ static int dhcp_identifier_set_duid_ll(const uint8_t *addr, size_t addr_len, uin unaligned_write_be16(&ret_duid->ll.htype, arp_type); memcpy(ret_duid->ll.haddr, addr, addr_len); - *ret_len = sizeof(ret_duid->type) + sizeof(ret_duid->ll.htype) + addr_len; + *ret_len = offsetof(struct duid, ll.haddr) + addr_len; return 0; } @@ -146,7 +146,7 @@ int dhcp_identifier_set_duid_en(bool test_mode, struct duid *ret_duid, size_t *r hash = htole64(siphash24(&machine_id, sizeof(machine_id), HASH_KEY.bytes)); memcpy(ret_duid->en.id, &hash, sizeof(ret_duid->en.id)); - *ret_len = sizeof(ret_duid->type) + sizeof(ret_duid->en); + *ret_len = offsetof(struct duid, en.id) + sizeof(ret_duid->en.id); if (test_mode) assert_se(memcmp(ret_duid, (const uint8_t[]) { 0x00, 0x02, 0x00, 0x00, 0xab, 0x11, 0x61, 0x77, 0x40, 0xde, 0x13, 0x42, 0xc3, 0xa2 }, *ret_len) == 0); @@ -166,9 +166,9 @@ static int dhcp_identifier_set_duid_uuid(struct duid *ret_duid, size_t *ret_len) return r; unaligned_write_be16(&ret_duid->type, DUID_TYPE_UUID); - memcpy(ret_duid->raw.data, &machine_id, sizeof(machine_id)); + memcpy(&ret_duid->uuid.uuid, &machine_id, sizeof(machine_id)); - *ret_len = sizeof(ret_duid->type) + sizeof(machine_id); + *ret_len = offsetof(struct duid, uuid.uuid) + sizeof(machine_id); return 0; } |