From 3e464f2c68011375632c2c868e25641ad95ebc45 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 19 Aug 2008 11:17:26 -0700 Subject: [PATCH] Add functions for reporting dhcp client statistics. --- include/dhcp-client.h | 4 ++++ lib/dhcp-client.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/dhcp-client.h b/include/dhcp-client.h index 9019ff116..390914341 100644 --- a/include/dhcp-client.h +++ b/include/dhcp-client.h @@ -52,6 +52,10 @@ void dhclient_force_renew(struct dhclient *, int deadline); bool dhclient_is_bound(const struct dhclient *); bool dhclient_changed(struct dhclient *); +const char *dhclient_get_state(const struct dhclient *); +unsigned int dhclient_get_state_elapsed(const struct dhclient *); +unsigned int dhclient_get_lease_remaining(const struct dhclient *); + uint32_t dhclient_get_ip(const struct dhclient *); uint32_t dhclient_get_netmask(const struct dhclient *); uint32_t dhclient_get_router(const struct dhclient *); diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index 2c7e48768..9df0c6c6c 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -305,6 +305,29 @@ dhclient_changed(struct dhclient *cli) return changed; } +/* Returns 'cli''s current state, as a string. The caller must not modify or + * free the string. */ +const char * +dhclient_get_state(const struct dhclient *cli) +{ + return state_name(cli->state); +} + +/* Returns the number of seconds spent so far in 'cli''s current state. */ +unsigned int +dhclient_get_state_elapsed(const struct dhclient *cli) +{ + return elapsed_in_this_state(cli); +} + +/* If 'cli' is bound, returns the number of seconds remaining in its lease; + * otherwise, returns 0. */ +unsigned int +dhclient_get_lease_remaining(const struct dhclient *cli) +{ + return dhclient_is_bound(cli) ? cli->lease_expiration - time_now() : 0; +} + /* If 'cli' is bound to an IP address, returns that IP address; otherwise, * returns 0. */ uint32_t -- 2.43.0