diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-07-28 15:28:07 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-07-28 15:28:07 -0700 |
commit | 3929693a476aea7761477213b6497df09f86359d (patch) | |
tree | c64f2e3f7dd094eebc9a9a33cafd91d25d7e79c8 /tools/dhcp-test.c | |
parent | 7804013bd84c430cf44cbbc23b9848632d67ee83 (diff) | |
download | connman-3929693a476aea7761477213b6497df09f86359d.tar.gz connman-3929693a476aea7761477213b6497df09f86359d.tar.bz2 connman-3929693a476aea7761477213b6497df09f86359d.zip |
Fix timer handling for DHCP library test tool
Diffstat (limited to 'tools/dhcp-test.c')
-rw-r--r-- | tools/dhcp-test.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/tools/dhcp-test.c b/tools/dhcp-test.c index cf4ff71d..bf7b7601 100644 --- a/tools/dhcp-test.c +++ b/tools/dhcp-test.c @@ -46,16 +46,9 @@ static void sig_term(int sig) g_main_loop_quit(main_loop); } -static void print_timestamp(void) +static void print_elapsed(void) { - GTimeVal timestamp; gdouble elapsed; - char *str; - - g_get_current_time(×tamp); - str = g_time_val_to_iso8601(×tamp); - printf("=== %s ===\n", str); - g_free(str); elapsed = g_timer_elapsed(timer, NULL); @@ -91,9 +84,9 @@ static void handle_error(GDHCPClientError error) static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data) { - printf("No Lease Available!\n"); + print_elapsed(); - print_timestamp(); + printf("No lease available\n"); g_main_loop_quit(main_loop); } @@ -103,6 +96,10 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data) GList *list, *option_value = NULL; char *address; + print_elapsed(); + + printf("Leave available\n"); + address = g_dhcp_client_get_address(dhcp_client); printf("address %s\n", address); if (address == NULL) @@ -123,8 +120,6 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data) option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME); for (list = option_value; list; list = list->next) printf("hostname %s\n", (char *) list->data); - - print_timestamp(); } int main(int argc, char *argv[]) @@ -143,8 +138,6 @@ int main(int argc, char *argv[]) printf("Create DHCP client for interface %d\n", index); - timer = g_timer_new(); - dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error); if (dhcp_client == NULL) { handle_error(error); @@ -168,10 +161,10 @@ int main(int argc, char *argv[]) main_loop = g_main_loop_new(NULL, FALSE); - print_timestamp(); - printf("Start DHCP operation\n"); + timer = g_timer_new(); + g_dhcp_client_start(dhcp_client); memset(&sa, 0, sizeof(sa)); @@ -181,11 +174,11 @@ int main(int argc, char *argv[]) g_main_loop_run(main_loop); + g_timer_destroy(timer); + g_dhcp_client_unref(dhcp_client); g_main_loop_unref(main_loop); - g_timer_destroy(timer); - return 0; } |