dhcp: add function nm_dhcp_lease_data_parse_u32()

Add a function to parse 32-bit integer values from a DHCP option.
This commit is contained in:
Beniamino Galvani
2024-10-08 11:31:19 +02:00
parent 1db882ca63
commit 1fa08e7d1b
2 changed files with 27 additions and 0 deletions

View File

@@ -934,6 +934,27 @@ nm_dhcp_lease_data_parse_u16(const guint8 *data,
return TRUE;
}
gboolean
nm_dhcp_lease_data_parse_u32(const guint8 *data,
gsize n_data,
uint32_t *out_val,
const char *iface,
int addr_family,
guint option)
{
if (n_data != 4) {
nm_dhcp_lease_log_invalid_option(iface,
addr_family,
option,
"invalid option length %lu",
(unsigned long) n_data);
return FALSE;
}
*out_val = unaligned_read_be32(data);
return TRUE;
}
gboolean
nm_dhcp_lease_data_parse_mtu(const guint8 *data,
gsize n_data,

View File

@@ -74,6 +74,12 @@ gboolean nm_dhcp_lease_data_parse_u16(const guint8 *data,
const char *iface,
int addr_family,
guint option);
gboolean nm_dhcp_lease_data_parse_u32(const guint8 *data,
gsize n_data,
uint32_t *out_val,
const char *iface,
int addr_family,
guint option);
gboolean nm_dhcp_lease_data_parse_mtu(const guint8 *data,
gsize n_data,
guint16 *out_val,