diff options
author | Tom Gundersen <teg@jklm.no> | 2014-01-05 23:01:32 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-01-05 23:01:38 +0100 |
commit | 9f9a964f195df68175cd3d5c9c90a476fa474073 (patch) | |
tree | 8c5d4ec72f6ac08dda3a2a2d72007cb23e09737c /src/libsystemd-dhcp/dhcp-client.c | |
parent | 146ccaafd5c9d4f2798240b049f595f70f45f77b (diff) |
libsystemd-dhcp: expose received DNS server
Diffstat (limited to 'src/libsystemd-dhcp/dhcp-client.c')
-rw-r--r-- | src/libsystemd-dhcp/dhcp-client.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c index f6a6211022..dbec869816 100644 --- a/src/libsystemd-dhcp/dhcp-client.c +++ b/src/libsystemd-dhcp/dhcp-client.c @@ -41,6 +41,7 @@ struct DHCPLease { be32_t server_address; be32_t subnet_mask; be32_t router; + be32_t dns; }; typedef struct DHCPLease DHCPLease; @@ -209,6 +210,33 @@ int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr) return 0; } +int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr *addr) +{ + assert_return(client, -EINVAL); + assert_return(addr, -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->dns) + addr->s_addr = client->lease->dns; + else + return -ENOENT; + + break; + } + + return 0; +} + int sd_dhcp_client_prefixlen(const struct in_addr *addr) { int len = 0; @@ -727,6 +755,12 @@ static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option, break; + case DHCP_OPTION_DOMAIN_NAME_SERVER: + if (len >= 4) + memcpy(&lease->dns, option, 4); + + break; + case DHCP_OPTION_RENEWAL_T1_TIME: if (len == 4) { memcpy(&val, option, 4); |