n-dhcp4: add n_dhcp4_client_lease_get_server_identifier()

Add new API to query the server identifier of a lease.
This commit is contained in:
Beniamino Galvani 2020-07-15 17:22:51 +02:00
parent ae7d1e2b7a
commit c25aed5051
3 changed files with 28 additions and 0 deletions

View file

@ -36,6 +36,7 @@ global:
n_dhcp4_client_lease_get_yiaddr;
n_dhcp4_client_lease_get_siaddr;
n_dhcp4_client_lease_get_lifetime;
n_dhcp4_client_lease_get_server_identifier;
n_dhcp4_client_lease_query;
n_dhcp4_client_lease_select;
n_dhcp4_client_lease_accept;

View file

@ -241,6 +241,32 @@ _c_public_ void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint
*ns_lifetimep = lease->lifetime;
}
/**
* n_dhcp4_client_lease_get_server_identifier() - get the server identifier
* @lease: the lease to operate on
* @addr: return argument for the server identifier
*
* Gets the address contained in the server-identifier DHCP option, in network
* byte order.
*
* Return: 0 on success, negative error code on failure.
*/
_c_public_ int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *lease, struct in_addr *addr) {
uint8_t *data;
size_t n_data;
int r;
r = n_dhcp4_incoming_query(lease->message, N_DHCP4_OPTION_SERVER_IDENTIFIER, &data, &n_data);
if (r)
return r;
if (n_data < sizeof(struct in_addr))
return N_DHCP4_E_MALFORMED;
memcpy(addr, data, sizeof(struct in_addr));
return 0;
}
/**
* n_dhcp4_client_lease_query() - query the lease for an option
* @lease: the lease to operate on

View file

@ -171,6 +171,7 @@ void n_dhcp4_client_lease_get_siaddr(NDhcp4ClientLease *lease, struct in_addr *s
void n_dhcp4_client_lease_get_basetime(NDhcp4ClientLease *lease, uint64_t *ns_basetimep);
void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint64_t *ns_lifetimep);
int n_dhcp4_client_lease_query(NDhcp4ClientLease *lease, uint8_t option, uint8_t **datap, size_t *n_datap);
int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *lease, struct in_addr *addr);
int n_dhcp4_client_lease_select(NDhcp4ClientLease *lease);
int n_dhcp4_client_lease_accept(NDhcp4ClientLease *lease);