*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <net/ethernet.h>
#include <linux/if_arp.h>
-#include <gdhcp.h>
+#include <gdhcp/gdhcp.h>
static GTimer *timer;
-static GMainLoop *main_loop = NULL;
+static GMainLoop *main_loop;
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);
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);
}
GList *list, *option_value = NULL;
char *address;
+ print_elapsed();
+
+ printf("Lease available\n");
+
address = g_dhcp_client_get_address(dhcp_client);
printf("address %s\n", address);
if (address == NULL)
for (list = option_value; list; list = list->next)
printf("domain-name-servers %s\n", (char *) list->data);
+ option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
+ for (list = option_value; list; list = list->next)
+ printf("domain-name %s\n", (char *) list->data);
+
option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
for (list = option_value; list; list = list->next)
printf("routers %s\n", (char *) list->data);
- print_timestamp();
+ 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);
}
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);
g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
main_loop = g_main_loop_new(NULL, FALSE);
- print_timestamp();
-
printf("Start DHCP operation\n");
- g_dhcp_client_start(dhcp_client);
+ timer = g_timer_new();
+
+ g_dhcp_client_start(dhcp_client, NULL);
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;
g_main_loop_run(main_loop);
+ g_timer_destroy(timer);
+
g_dhcp_client_unref(dhcp_client);
g_main_loop_unref(main_loop);