diff options
author | Tom Gundersen <teg@jklm.no> | 2014-03-03 16:46:10 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-03-03 16:48:02 +0100 |
commit | 0ad853bc06dea1db5740caf59f404d274fa5e3c9 (patch) | |
tree | 1aba096fcf3450a64bffb11195b6188bc9b47728 | |
parent | ce78df79b88d02d36cbf9e39e70ecb871750e16d (diff) |
sd-dhcp-lease: add sd_dhcp_lease_get_server_identifier()
-rw-r--r-- | src/libsystemd-network/sd-dhcp-lease.c | 32 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-lease.h | 1 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 722dd0a419..6bd9728377 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -126,6 +126,15 @@ int sd_dhcp_lease_get_netmask(sd_dhcp_lease *lease, struct in_addr *addr) { return 0; } +int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr) { + assert_return(lease, -EINVAL); + assert_return(addr, -EINVAL); + + addr->s_addr = lease->server_address; + + return 0; +} + sd_dhcp_lease *sd_dhcp_lease_ref(sd_dhcp_lease *lease) { if (lease) assert_se(REFCNT_INC(lease->n_ref) >= 2); @@ -329,6 +338,18 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) { fprintf(f, "NETMASK=%s\n", string); + r = sd_dhcp_lease_get_server_identifier(lease, &address); + if (r >= 0) { + string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN); + if (!string) { + r = -errno; + goto finish; + } + + fprintf(f, + "SERVER_ADDRESS=%s\n", string); + } + r = sd_dhcp_lease_get_mtu(lease, &mtu); if (r >= 0) fprintf(f, "MTU=%" PRIu16 "\n", mtu); @@ -367,7 +388,7 @@ finish: int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) { _cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL; _cleanup_free_ char *address = NULL, *router = NULL, *netmask = NULL, - *mtu = NULL; + *server_address = NULL, *mtu = NULL; struct in_addr addr; int r; @@ -382,6 +403,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) { "ADDRESS", &address, "ROUTER", &router, "NETMASK", &netmask, + "SERVER_IDENTIFIER", &server_address, "MTU", &mtu, "DOMAINNAME", &lease->domainname, "HOSTNAME", &lease->hostname, @@ -413,6 +435,14 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) { lease->subnet_mask = addr.s_addr; + if (server_address) { + r = inet_pton(AF_INET, server_address, &addr); + if (r < 0) + return r; + + lease->server_address = addr.s_addr; + } + if (mtu) { uint16_t u; if (sscanf(mtu, "%" SCNu16, &u) > 0) diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h index 5b34b2a070..7e737a90c0 100644 --- a/src/systemd/sd-dhcp-lease.h +++ b/src/systemd/sd-dhcp-lease.h @@ -33,6 +33,7 @@ sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease); int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr); int sd_dhcp_lease_get_netmask(sd_dhcp_lease *lease, struct in_addr *addr); int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr); +int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr); int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size); int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu); int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname); |