[dhcp-agent-commits] dhcp-agent/src dhcp-client-cache.c,1.16,1.17 dhcp-client-cache.h,1.6,1.7 dhcp-c
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-06 05:34:39
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv20954/src Modified Files: dhcp-client-cache.c dhcp-client-cache.h dhcp-client.c dhcp-client.h Log Message: added -s options to client (for status) Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-client-cache.c 5 May 2003 01:23:37 -0000 1.16 --- dhcp-client-cache.c 6 Jul 2003 05:34:33 -0000 1.17 *************** *** 140,150 **** } ! /* check if cache is empty. */ ! int client_cache_is_empty(client_cache_t *cc) { int retval; char *fname; ! fname = get_fname(cc); if(file_exists(fname)) retval = 0; --- 140,153 ---- } ! static int client_cache_is_empty_proc(client_cache_t *cc, int tmp) { int retval; char *fname; ! if(tmp) ! fname = get_fname_tmp(cc); ! else ! fname = get_fname(cc); ! if(file_exists(fname)) retval = 0; *************** *** 157,160 **** --- 160,175 ---- } + /* check if cache is empty. */ + int client_cache_is_empty(client_cache_t *cc) + { + return client_cache_is_empty_proc(cc, 0); + } + + /* check if temporary cache is empty. */ + int client_cache_is_empty_tmp(client_cache_t *cc) + { + return client_cache_is_empty_proc(cc, 1); + } + /* check if a cache entry is for a timer option. */ static int is_timer_option(cache_entry_t *ce) *************** *** 332,333 **** --- 347,381 ---- return client_cache_load_options_proc(cc, use_tmp, is_timer_option); } + + void client_pretty_print_cache(client_cache_t *cc, uint8_t use_tmp) + { + dhcp_opt_t *option; + cache_entry_t *ce; + const char *name; + char *val; + list_t *options; + + if((options = client_cache_load_options_proc(cc, use_tmp, NULL)) == NULL) { + FATAL_MESSAGE("could not load cached lease"); + } + + INFO_MESSAGE("Lease contents:"); + + list_rewind(cc->vars); + while((ce = list_next(cc->vars)) != NULL) { + + + option = dhcp_opt_create_from_host_string(ce->tag, ce->value); + + name = dhcp_option_printable_string_get(dhcp_opt_get_tag(option)); + val = dhcp_opt_get_internal_string(option); + + INFO_MESSAGE("%s : %s", name, val); + + xfree(val); + } + + INFO_MESSAGE(" "); + return; + } + Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client-cache.h 4 May 2003 18:50:41 -0000 1.6 --- dhcp-client-cache.h 6 Jul 2003 05:34:36 -0000 1.7 *************** *** 41,47 **** --- 41,49 ---- extern void client_cache_delete_cache(client_cache_t *cc); extern int client_cache_is_empty(client_cache_t *cc); + extern int client_cache_is_empty_tmp(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_options(client_cache_t *cc, uint8_t use_tmp); extern list_t *client_cache_load_timer_options(client_cache_t *cc, uint8_t use_tmp); + extern void client_pretty_print_cache(client_cache_t *cc, uint8_t use_tmp); #endif /* DHCP_CLIENT_CACHE_H */ Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** dhcp-client.c 2 Jul 2003 15:18:22 -0000 1.32 --- dhcp-client.c 6 Jul 2003 05:34:36 -0000 1.33 *************** *** 43,46 **** --- 43,47 ---- static void do_clear_cache(char *interface); static void do_client(char *interface); + static void do_status(char *interface); /* command to string table. */ *************** *** 57,60 **** --- 58,62 ---- do_clear_cache, /* clear cache. */ do_client, /* initialize and run client. */ + do_status, /* get status info. */ }; *************** *** 74,77 **** --- 76,80 ---- interface_get_active, /* clear cache. */ interface_get_inactive, /* run client. */ + interface_get_active, /* get status. */ }; *************** *** 118,122 **** static void usage(char *s) { ! printf("usage: %s [-cpavkwt] [-l verbosity level] [-d directory]\n", s); printf("usage: %-*s [-i interface name] [ -m mac address ]\n", strlen(s), " "); exit(0); --- 121,125 ---- static void usage(char *s) { ! printf("usage: %s [-scpavkwt] [-l verbosity level] [-d directory]\n", s); printf("usage: %-*s [-i interface name] [ -m mac address ]\n", strlen(s), " "); exit(0); *************** *** 337,340 **** --- 340,377 ---- } + static void do_status(char *interface) + { + /* try to load up cache. */ + client_cache_t *cache; + + if((cache = client_cache_create(interface)) == NULL) { + FATAL_MESSAGE("could not create client cache"); + } + + if(client_cache_is_empty(cache)) { + + if(client_cache_is_empty_tmp(cache)) { + + + INFO_MESSAGE("No lease acquired for this interface."); + INFO_MESSAGE(" "); + + } else { + + INFO_MESSAGE("This lease has been offered but has not been acquired yet, or the client has not been able to receive an acknowledgement from the + server yet."); + INFO_MESSAGE(" "); + client_pretty_print_cache(cache, 1); + + } + + } else { + + client_pretty_print_cache(cache, 0); + } + + return; + } + /* do client: perform dhcp client proper functions. */ static void do_client(char *interface) *************** *** 471,475 **** INFO_MESSAGE(" "); ! while((c = getopt(argc, argv, "tpcdavi:m:kwh:l:H:")) != -1) { switch (c) { --- 508,512 ---- INFO_MESSAGE(" "); ! while((c = getopt(argc, argv, "stpcdavi:m:kwh:l:H:")) != -1) { switch (c) { *************** *** 513,516 **** --- 550,557 ---- } + break; + + case 's': + command_code = DO_STATUS; break; Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-client.h 26 Jun 2003 23:56:42 -0000 1.20 --- dhcp-client.h 6 Jul 2003 05:34:36 -0000 1.21 *************** *** 71,75 **** /* client commands. */ ! enum client_commands { DO_VERSION = 0, DO_KILL, DO_WAKE, DO_CLEAR, DO_CLIENT }; /* DHCP client states. */ --- 71,75 ---- /* client commands. */ ! enum client_commands { DO_VERSION = 0, DO_KILL, DO_WAKE, DO_CLEAR, DO_CLIENT, DO_STATUS }; /* DHCP client states. */ |