-/* $OpenBSD: dhcp6leased.h,v 1.5 2024/06/03 18:10:04 florian Exp $ */
+/* $OpenBSD: dhcp6leased.h,v 1.6 2024/06/05 16:14:12 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef nitems
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
#define _PATH_LOCKFILE "/dev/dhcp6leased.lock"
#define _PATH_CONF_FILE "/etc/dhcp6leased.conf"
#define _PATH_CTRL_SOCKET "/dev/dhcp6leased.sock"
-/* $OpenBSD: frontend.c,v 1.10 2024/06/05 10:25:07 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.11 2024/06/05 16:14:12 florian Exp $ */
/*
* Copyright (c) 2017, 2021, 2024 Florian Obser <florian@openbsd.org>
struct dhcp_iapd iapd;
struct dhcp_iaprefix iaprefix;
struct dhcp_vendor_class vendor_class;
+ size_t i;
ssize_t len;
uint16_t request_option_code, elapsed_time;
+ const uint16_t options[] = {DHO_SOL_MAX_RT,
+ DHO_INF_MAX_RT};
uint8_t *p;
switch (message_type) {
}
opt_hdr.code = htons(DHO_ORO);
- opt_hdr.len = htons(2 * 2);
+ opt_hdr.len = htons(sizeof(request_option_code) * nitems(options));
memcpy(p, &opt_hdr, sizeof(struct dhcp_option_hdr));
p += sizeof(struct dhcp_option_hdr);
- request_option_code = htons(DHO_SOL_MAX_RT);
- memcpy(p, &request_option_code, sizeof(uint16_t));
- p += sizeof(uint16_t);
- request_option_code = htons(DHO_INF_MAX_RT);
- memcpy(p, &request_option_code, sizeof(uint16_t));
- p += sizeof(uint16_t);
+ for (i = 0; i < nitems(options); i++) {
+ request_option_code = htons(options[i]);
+ memcpy(p, &request_option_code, sizeof(uint16_t));
+ p += sizeof(uint16_t);
+ }
opt_hdr.code = htons(DHO_ELAPSED_TIME);
opt_hdr.len = htons(2);