Add functions for reporting dhcp client statistics.
authorBen Pfaff <blp@nicira.com>
Tue, 19 Aug 2008 18:17:26 +0000 (11:17 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 26 Aug 2008 18:51:17 +0000 (11:51 -0700)
include/dhcp-client.h
lib/dhcp-client.c

index 9019ff1..3909143 100644 (file)
@@ -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 *);
index 2c7e487..9df0c6c 100644 (file)
@@ -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