diff options
author | Tom Gundersen <teg@jklm.no> | 2014-01-13 23:48:28 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-01-16 20:32:08 +0100 |
commit | 1346b1f0388f4100bb3c2a2bb23bc881769c020c (patch) | |
tree | 2e6aa6dc4d2a834156bb082408e9220018c039f6 /src/libsystemd | |
parent | 6fc73498945da749744041d4e10cf8dfac5c3bc6 (diff) |
sd-dhcp-client/networkd: add transient hostname 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 76abcbd2ac..c5d8371a98 100644 --- a/src/libsystemd/sd-dhcp-client.c +++ b/src/libsystemd/sd-dhcp-client.c @@ -43,6 +43,7 @@ struct DHCPLease { be32_t router; struct in_addr **dns; uint16_t mtu; + char *hostname; }; typedef struct DHCPLease DHCPLease; @@ -241,6 +242,33 @@ int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr ***addr) return 0; } +int sd_dhcp_client_get_hostname(sd_dhcp_client *client, const char **hostname) +{ + assert_return(client, -EINVAL); + assert_return(hostname, -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->hostname) + *hostname = client->lease->hostname; + else + return -ENOENT; + + break; + } + + return 0; +} + int sd_dhcp_client_prefixlen(const struct in_addr *addr) { int len = 0; @@ -829,6 +857,14 @@ static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option, break; + case DHCP_OPTION_HOST_NAME: + if (len >= 1) { + free(lease->hostname); + lease->hostname = strndup((const char *)option, len); + } + + break; + case DHCP_OPTION_RENEWAL_T1_TIME: if (len == 4) { memcpy(&val, option, 4); |