diff options
author | Tom Gundersen <teg@jklm.no> | 2014-01-18 15:47:57 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-01-18 17:52:10 +0100 |
commit | 039ebe6aebaebcaa18375b33caf1db5fe2551621 (patch) | |
tree | ef0ed8c3ea7d598b3610948df5f64a2a23cc52e6 /src/libsystemd | |
parent | bcbca8291fe3beaed36dd672d8b544840cfc49de (diff) |
sd-dhcp-client/networkd: add domainname support
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-dhcp-client.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libsystemd/sd-dhcp-client.c b/src/libsystemd/sd-dhcp-client.c index 26ed35e5fe..908f844671 100644 --- a/src/libsystemd/sd-dhcp-client.c +++ b/src/libsystemd/sd-dhcp-client.c @@ -44,6 +44,7 @@ struct DHCPLease { struct in_addr *dns; size_t dns_size; uint16_t mtu; + char *domainname; char *hostname; }; @@ -237,6 +238,32 @@ int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr **addr, size_t return 0; } +int sd_dhcp_client_get_domainname(sd_dhcp_client *client, const char **domainname) { + assert_return(client, -EINVAL); + assert_return(domainname, -EINVAL); + + switch (client->state) { + case DHCP_STATE_INIT: + case DHCP_STATE_SELECTING: + case DHCP_STATE_INIT_REBOOT: + case DHCP_STATE_REBOOTING: + case DHCP_STATE_REQUESTING: + return -EADDRNOTAVAIL; + + case DHCP_STATE_BOUND: + case DHCP_STATE_RENEWING: + case DHCP_STATE_REBINDING: + if (client->lease->domainname) + *domainname = client->lease->domainname; + else + return -ENOENT; + + break; + } + + return 0; +} + int sd_dhcp_client_get_hostname(sd_dhcp_client *client, const char **hostname) { assert_return(client, -EINVAL); assert_return(hostname, -EINVAL); @@ -336,6 +363,7 @@ static void lease_free(DHCPLease *lease) { return; free(lease->hostname); + free(lease->domainname); free(lease->dns); free(lease); } @@ -832,6 +860,14 @@ static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option, break; + case DHCP_OPTION_DOMAIN_NAME: + if (len >= 1) { + free(lease->domainname); + lease->domainname = strndup((const char *)option, len); + } + + break; + case DHCP_OPTION_HOST_NAME: if (len >= 1) { free(lease->hostname); |