[dhcp-agent-commits] dhcp-agent/src dhcp-arp-discovery.c,1.3,1.4 dhcp-cache-entry.c,1.5,1.6 dhcp-cli
Status: Alpha
                
                Brought to you by:
                
                    actmodern
                    
                
            Update of /cvsroot/dhcp-agent/dhcp-agent/src
In directory sc8-pr-cvs1:/tmp/cvs-serv25981/src
Modified Files:
	dhcp-arp-discovery.c dhcp-cache-entry.c dhcp-client-cache.c 
	dhcp-client-conf.c dhcp-client-states.c dhcp-client.c 
	dhcp-com.c dhcp-conf.c dhcp-convert.c dhcp-icmp-discovery.c 
	dhcp-interface.c dhcp-librawnet.h dhcp-libutil.h dhcp-list.c 
	dhcp-sniff.c dhcp-sysconf.c dhcp-timer.c 
Log Message:
redid list object
Index: dhcp-arp-discovery.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp-discovery.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** dhcp-arp-discovery.c	16 Nov 2002 00:23:42 -0000	1.3
--- dhcp-arp-discovery.c	2 Jan 2003 04:23:01 -0000	1.4
***************
*** 41,49 ****
      list_t *argument_list = data;
  
!     net = argument_list->data;
!     if(argument_list->next)
!         addr = argument_list->next->data;
!     else {
!         WARN_MESSAGE("check arp reply: no address passed to function -- skipping");
          return 0;
      }
--- 41,49 ----
      list_t *argument_list = data;
  
!     net = list_first(argument_list);
!     addr = list_second(argument_list);
! 
!     if(addr == NULL) {
!         WARN_MESSAGE("no address passed to function -- skipping");
          return 0;
      }
***************
*** 71,80 ****
                                    eth_addr_t *mac_addr)
  {
!     list_t *arg_list = NULL;
      unsigned char *sender_addr;
      int retval;
  
!     arg_list = add_to_list(arg_list, &address);
!     arg_list = add_to_list(arg_list, net);
  
      /* 0 for source ip, address to discover for dest, our
--- 71,81 ----
                                    eth_addr_t *mac_addr)
  {
!     list_t *arg_list;
      unsigned char *sender_addr;
      int retval;
  
!     arg_list = list_create();
!     list_add(arg_list, &address);
!     list_add(arg_list, net);
  
      /* 0 for source ip, address to discover for dest, our
***************
*** 102,111 ****
              memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN);
  
!             /* just free up pair. FIXME: this isn't good because we're 
!              * breaking the list blackbox. we need a better way to do this. 
!              * the datums don't need to be freed since we keep them on the stack. */
! 
!             xfree(arg_list->next);
!             xfree(arg_list);
  
              return 0;
--- 103,107 ----
              memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN);
  
!             list_destroy(arg_list, NULL);
  
              return 0;
***************
*** 114,117 ****
--- 110,114 ----
              /* wops error. this is bad. */
              ERROR_MESSAGE("received error from raw network handler.");
+             list_destroy(arg_list, NULL);
              return 1;
  
***************
*** 123,129 ****
      }
  
!     /* FIXME: ditto (see above) */
!     xfree(arg_list->next);
!     xfree(arg_list);
  
      WARN_MESSAGE("timeout on discovery.");
--- 120,124 ----
      }
  
!     list_destroy(arg_list, NULL);
  
      WARN_MESSAGE("timeout on discovery.");
Index: dhcp-cache-entry.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** dhcp-cache-entry.c	16 Dec 2002 10:04:32 -0000	1.5
--- dhcp-cache-entry.c	2 Jan 2003 04:23:01 -0000	1.6
***************
*** 68,72 ****
  void cache_entry_purge_list(list_t *cache_list)
  {
!     purge_list(cache_list, cache_entry_destroy_l);
      return;
  }
--- 68,72 ----
  void cache_entry_purge_list(list_t *cache_list)
  {
!     list_destroy(cache_list, cache_entry_destroy_l);
      return;
  }
Index: dhcp-client-cache.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** dhcp-client-cache.c	30 Dec 2002 03:41:51 -0000	1.12
--- dhcp-client-cache.c	2 Jan 2003 04:23:01 -0000	1.13
***************
*** 47,51 ****
      cc = xmalloc(sizeof(client_cache_t));
      cc->interface = interface; /* don't copy just point. */
!     cc->vars = NULL;
  
      return cc;
--- 47,51 ----
      cc = xmalloc(sizeof(client_cache_t));
      cc->interface = interface; /* don't copy just point. */
!     cc->vars = list_create();
  
      return cc;
***************
*** 57,61 ****
  {
      cache_entry_purge_list(cc->vars);
!     cc->vars = NULL;
      return;
  }
--- 57,61 ----
  {
      cache_entry_purge_list(cc->vars);
!     cc->vars = list_create();
      return;
  }
***************
*** 207,211 ****
  
      while((cache_entry = read_next_cache_var(varfile)) != NULL)
!         cc->vars = add_to_list(cc->vars, cache_entry);
  
      destroy_varfile(varfile);
--- 207,211 ----
  
      while((cache_entry = read_next_cache_var(varfile)) != NULL)
!         list_add(cc->vars, cache_entry);
  
      destroy_varfile(varfile);
***************
*** 292,306 ****
                                             void *(*convert_func) (unsigned char tag, char *string))
  {
!     list_t *options = NULL;
!     list_t *cache;
      cache_entry_t *ce;
      void *data;
  
!     for(cache = cc->vars; cache; cache = cache->next) {
  
-         ce = cache->data;
          data = convert_func(atoi(ce->name), ce->value);
          if(data != NULL) { /* we need to silently ignore nulls here so that the timer only converter works. */
!             options = add_to_list(options, data);
          }
  
--- 292,307 ----
                                             void *(*convert_func) (unsigned char tag, char *string))
  {
!     list_t *options;
      cache_entry_t *ce;
      void *data;
  
!     options = list_create();
! 
!     list_rewind(cc->vars);
!     while((ce = list_next(cc->vars)) != NULL) {
  
          data = convert_func(atoi(ce->name), ce->value);
          if(data != NULL) { /* we need to silently ignore nulls here so that the timer only converter works. */
!             list_add(options, data);
          }
  
***************
*** 318,322 ****
  {
      FILE *fp;
-     list_t *list_ptr;
      char *name;
      char *val;
--- 319,322 ----
***************
*** 332,342 ****
          return -1;
  
!     for(list_ptr = options; list_ptr; list_ptr = list_ptr->next) {
  
          /* Run coversion routines to store internally in 
           * serialized (string) state. */
  
-         opt = list_ptr->data;
- 
          if(option_convert_handlers[opt->tag].serialize == NULL)
              continue;
--- 332,341 ----
          return -1;
  
!     list_rewind(options);
!     while((opt = list_next(options)) != NULL) {
  
          /* Run coversion routines to store internally in 
           * serialized (string) state. */
  
          if(option_convert_handlers[opt->tag].serialize == NULL)
              continue;
***************
*** 374,378 ****
                                                                            char *string))
  {
- 
      list_t *options;
  
--- 373,376 ----
Index: dhcp-client-conf.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** dhcp-client-conf.c	23 Dec 2002 00:51:24 -0000	1.14
--- dhcp-client-conf.c	2 Jan 2003 04:23:01 -0000	1.15
***************
*** 36,39 ****
--- 36,40 ----
  #include "dhcp-options-strings.h"
  
+ /* FIXME: check for destroy params mem leak. */
  
  /* * * * * * * * * * * * * * * * * * *
***************
*** 236,242 ****
      int i;
  
!     for(;strings; strings = strings->next) {
! 
!         option_string = strings->data;
  
          for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) {
--- 237,242 ----
      int i;
  
!     list_rewind(strings);
!     for(option_string = list_next(strings); option_string; option_string = list_next(strings)) {
  
          for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) {
***************
*** 386,393 ****
  
      /* now process group. */
!     for(directive_list = directive_data;
!         directive_list;directive_list = directive_list->next) {
  
-         directive = directive_list->data;
          if(directive_handlers[directive->command_code](params, directive, group_type, group_data))
              return 1;
--- 386,393 ----
  
      /* now process group. */
!     directive_list = directive_data;
!     list_rewind(directive_list);
!     while((directive = list_next(directive_list)) != NULL) {
  
          if(directive_handlers[directive->command_code](params, directive, group_type, group_data))
              return 1;
***************
*** 406,411 ****
      args = directive->arguments;
  
!     var_symbol = args->data;
!     var_value = args->next->next->data;
  
      if(client_conf_set_variable(params, *var_symbol, var_value)) {
--- 406,411 ----
      args = directive->arguments;
  
!     var_symbol = list_get_by_index(args, 0);
!     var_value = list_get_by_index(args, 3);
  
      if(client_conf_set_variable(params, *var_symbol, var_value)) {
***************
*** 424,428 ****
  
      args = directive->arguments;
!     string_list = args->data;
  
      if(fill_option_bit_array_from_string_list(string_list, params->request_options))
--- 424,428 ----
  
      args = directive->arguments;
!     string_list = list_first(args);
  
      if(fill_option_bit_array_from_string_list(string_list, params->request_options))
***************
*** 439,443 ****
  
      args = directive->arguments;
!     string_list = args->data;
  
      if(fill_option_bit_array_from_string_list(string_list, params->required_options))
--- 439,443 ----
  
      args = directive->arguments;
!     string_list = list_first(args);
  
      if(fill_option_bit_array_from_string_list(string_list, params->required_options))
***************
*** 455,465 ****
      conf_params_t *new_params;
      directive_group_t new_group_type;
  
!     /* FIXME: check for the same group specified twice.
!      * this gives us a bit of compression in the unlikely
!      * case of a broken config file. */
! 
!     args = directive_data;
!     server_symbol = args->data;
  
      switch(*server_symbol) {
--- 455,463 ----
      conf_params_t *new_params;
      directive_group_t new_group_type;
+     directive_t *directive;
  
!     directive = directive_data;
!     args = directive->arguments;
!     server_symbol = list_first(args);
  
      switch(*server_symbol) {
***************
*** 483,488 ****
      }
  
!     address_data = args->next->data;
!     directives = args->next->next->data;
      new_params = xcalloc(sizeof(conf_params_t));
  
--- 481,486 ----
      }
  
!     address_data = list_get_by_index(args, 1);
!     directives = list_get_by_index(args, 2);
      new_params = xcalloc(sizeof(conf_params_t));
  
***************
*** 490,494 ****
          return 1;
  
!     params->lower_params = add_to_list(params->lower_params, new_params);
  
      return 0;
--- 488,495 ----
          return 1;
  
!     if(params->lower_params == NULL)
!         params->lower_params = list_create();
! 
!     list_add(params->lower_params, new_params);
  
      return 0;
***************
*** 504,509 ****
      args = directive->arguments;
  
!     var_symbol = args->data;
!     var_value = args->next->next->data;
  
      if(client_conf_set_variable_boolean(params, *var_symbol, *var_value)) {
--- 505,510 ----
      args = directive->arguments;
  
!     var_symbol = list_get_by_index(args, 0);
!     var_value = list_get_by_index(args, 2);
  
      if(client_conf_set_variable_boolean(params, *var_symbol, *var_value)) {
***************
*** 526,529 ****
--- 527,531 ----
      cc->interface = interface;
      cc->conf_file = get_conf_options_fname(cc);
+     cc->parameters.lower_params = list_create();
  
      cc->parameters.group_type = DIRECTIVE_GROUP_NULL; /* set top level to catchall group. */
***************
*** 542,555 ****
      conf_params_t *lower_params;
  
!     for(params_list = params->lower_params;
!         params_list; params_list = params_list->next) {
! 
!         lower_params = params_list->data;
          params_destroy(lower_params, 0);
- 
      }
  
      if(params->client_hostname)
          xfree(params->client_hostname);
  
      if(!topflag)
--- 544,559 ----
      conf_params_t *lower_params;
  
!     params_list = params->lower_params;
!     list_rewind(params_list);
!     for(lower_params = list_next(params_list); lower_params;
!         lower_params = list_next(params_list))  {
          params_destroy(lower_params, 0);
      }
  
      if(params->client_hostname)
          xfree(params->client_hostname);
+ 
+     list_destroy(params->lower_params, NULL);
+     params->lower_params = NULL;
  
      if(!topflag)
Index: dhcp-client-states.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** dhcp-client-states.c	30 Dec 2002 21:54:37 -0000	1.23
--- dhcp-client-states.c	2 Jan 2003 04:23:01 -0000	1.24
***************
*** 47,60 ****
  static list_t *client_build_release_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options = NULL;
      dhcp_option_t *option;
  
      /* client_id: RFC2131 says we MAY */
      option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1));
!     options = add_to_list(options, option);
  
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_RELEASE_TM);
!     options = add_to_list(options, option);
  
      return options;
--- 47,62 ----
  static list_t *client_build_release_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options;
      dhcp_option_t *option;
  
+     options = list_create();
+ 
      /* client_id: RFC2131 says we MAY */
      option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1));
!     list_add(options, option);
  
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_RELEASE_TM);
!     list_add(options, option);
  
      return options;
***************
*** 65,84 ****
  static list_t *client_build_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options = NULL;
      dhcp_option_t *option;
      const char *hostname;
  
      /* dhcp max DHCP message size:
       * should go into globconf. */
      option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE);
!     options = add_to_list(options, option);
  
      /* client_id */
      option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1));
!     options = add_to_list(options, option);
  
      /* class_id */
      option = dhcp_build_class_id(dc->class_id);
!     options = add_to_list(options, option);
  
      /* hostname if available */
--- 67,87 ----
  static list_t *client_build_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options;
      dhcp_option_t *option;
      const char *hostname;
  
+     options = list_create();
      /* dhcp max DHCP message size:
       * should go into globconf. */
      option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE);
!     list_add(options, option);
  
      /* client_id */
      option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1));
!     list_add(options, option);
  
      /* class_id */
      option = dhcp_build_class_id(dc->class_id);
!     list_add(options, option);
  
      /* hostname if available */
***************
*** 87,91 ****
          /* if we have one set it. */
          option = dhcp_build_hostname(hostname);
!         options = add_to_list(options, option);
      }
  
--- 90,94 ----
          /* if we have one set it. */
          option = dhcp_build_hostname(hostname);
!         list_add(options, option);
      }
  
***************
*** 96,116 ****
  static list_t *client_build_discover_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options = NULL;
!     list_t *requested_options = NULL;
      dhcp_option_t *option;
  
      option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf));
      if(option == NULL) {
          WARN_MESSAGE("sending with empty parameter request list");
      } else {
!         options = add_to_list(options, option);
      }
  
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_DISCOVER_TM);
!     options = add_to_list(options, option);
  
      requested_options = client_build_option_list(dc);
!     options = join_lists(options, requested_options);
  
      return options;
--- 99,120 ----
  static list_t *client_build_discover_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options;
!     list_t *requested_options;
      dhcp_option_t *option;
  
+     options = list_create();
      option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf));
      if(option == NULL) {
          WARN_MESSAGE("sending with empty parameter request list");
      } else {
!         list_add(options, option);
      }
  
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_DISCOVER_TM);
!     list_add(options, option);
  
      requested_options = client_build_option_list(dc);
!     list_join(options, requested_options); /* this destroys requested_options */
  
      return options;
***************
*** 120,133 ****
  static list_t *client_build_request_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options = NULL;
!     list_t *requested_options = NULL;
      dhcp_option_t *option;
  
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_REQUEST_TM);
!     options = add_to_list(options, option);
  
      requested_options = client_build_option_list(dc);
!     options = join_lists(options, requested_options);
  
      return options;
--- 124,138 ----
  static list_t *client_build_request_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options;
!     list_t *requested_options;
      dhcp_option_t *option;
  
+     options = list_create();
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_REQUEST_TM);
!     list_add(options, option);
  
      requested_options = client_build_option_list(dc);
!     list_join(options, requested_options); /* this destroys requested_options */
  
      return options;
***************
*** 137,150 ****
  static list_t *client_build_renew_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options = NULL;
      dhcp_option_t *option;
  
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_REQUEST_TM);
!     options = add_to_list(options, option);
  
      /* client_id */
      option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1));
!     options = add_to_list(options, option);
  
      return options;
--- 142,156 ----
  static list_t *client_build_renew_option_list(dhcp_client_control_t *dc)
  {
!     list_t *options;
      dhcp_option_t *option;
  
+     options = list_create();
      /* dhcp message type. */
      option = dhcp_build_message_type(DHCP_REQUEST_TM);
!     list_add(options, option);
  
      /* client_id */
      option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1));
!     list_add(options, option);
  
      return options;
***************
*** 229,233 ****
  
      /* is rawnet happy with the packet? */
!     if(((!rawnet_is_valid(dc->rawnet)) "&&
  
          /* is it a DHCP packet? */
--- 235,239 ----
  
      /* is rawnet happy with the packet? */
!     if(((!rawnet_is_valid(dc->rawnet)) &&
  
          /* is it a DHCP packet? */
***************
*** 305,309 ****
  
      dhcp_client_update_secs(dc);
!     rawnet_dhcp_update(dc->rawnet, (uint16_t)dc->secs);
      return;
  }
--- 311,315 ----
  
      dhcp_client_update_secs(dc);
!     rawnet_dhcp_update(dc->rawnet, (uint16_t)dc->secs); /* FIXME: this may be an integer overflow. */
      return;
  }
***************
*** 316,320 ****
      timer_options = client_cache_load_option_timer_string_list(dc->cache, 0);
  
!     if(timer_options == NULL) {
          FATAL_MESSAGE("no timers to setup. we should have least one: lease time");
          exit(1);
--- 322,326 ----
      timer_options = client_cache_load_option_timer_string_list(dc->cache, 0);
  
!     if(list_get_len(timer_options) == 0) {
          FATAL_MESSAGE("no timers to setup. we should have least one: lease time");
          exit(1);
***************
*** 405,409 ****
  int client_discover_offer(dhcp_client_control_t *dc)
  {
!     list_t *options = NULL;
      int retval;
  
--- 411,415 ----
  int client_discover_offer(dhcp_client_control_t *dc)
  {
!     list_t *options;
      int retval;
  
***************
*** 460,471 ****
  
      if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS))
!         dc->rawnet->dhcp_p->options =
!             add_to_list(dc->rawnet->dhcp_p->options,
!                         dhcp_build_requested_ip_address(dhcp_get_yiaddr(dc->rawnet->dhcp_p)));
  
      if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_SERVER_IDENTIFIER))
!         dc->rawnet->dhcp_p->options =
!             add_to_list(dc->rawnet->dhcp_p->options,
!                         dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p)));
  
      /* dump cache file. */
--- 466,475 ----
  
      if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS))
!         list_add(dc->rawnet->dhcp_p->options,
!                  dhcp_build_requested_ip_address(dhcp_get_yiaddr(dc->rawnet->dhcp_p)));
  
      if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_SERVER_IDENTIFIER))
!         list_add(dc->rawnet->dhcp_p->options,
!                  dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p)));
  
      /* dump cache file. */
***************
*** 493,502 ****
      cache_options = client_cache_load_option_network_list(dc->cache, 0);
  
!     if(cache_options == NULL) {
          ERROR_MESSAGE("could not load cache.");
          return STATE_FATAL_ERROR;
      }
  
!     options = join_lists(options, cache_options);
  
      /* Our options cleared by build_* since they are passed
--- 497,507 ----
      cache_options = client_cache_load_option_network_list(dc->cache, 0);
  
!     if(list_get_len(cache_options) == 0) {
! 
          ERROR_MESSAGE("could not load cache.");
          return STATE_FATAL_ERROR;
      }
  
!     list_join(options, cache_options); /* destroys cache_options. */
  
      /* Our options cleared by build_* since they are passed
***************
*** 584,588 ****
  
      options = client_cache_load_option_string_list(dc->cache, 0);
!     if(options == NULL) {
          ERROR_MESSAGE("received empty configuration cache! cannot configure host");
          return STATE_FATAL_ERROR;
--- 589,593 ----
  
      options = client_cache_load_option_string_list(dc->cache, 0);
!     if(list_get_len(options) == 0) {
          ERROR_MESSAGE("received empty configuration cache! cannot configure host");
          return STATE_FATAL_ERROR;
***************
*** 672,676 ****
       * need them: FIXME, revamp into one network module that uses
       * raw or user level networking depending on our interface's
!      * state */
  
      rawnet_up(dc->rawnet);
--- 677,681 ----
       * need them: FIXME, revamp into one network module that uses
       * raw or user level networking depending on our interface's
!      * state. */
  
      rawnet_up(dc->rawnet);
***************
*** 697,702 ****
  
          cached_options = client_cache_load_option_string_list(dc->cache, 0);
!         if(cached_options != NULL)
!             do_sysconf_cleanup(cached_options, dc);
  
          cache_entry_purge_list(cached_options);
--- 702,706 ----
  
          cached_options = client_cache_load_option_string_list(dc->cache, 0);
!         do_sysconf_cleanup(cached_options, dc);
  
          cache_entry_purge_list(cached_options);
***************
*** 715,719 ****
      list_t *options;
      int retval;
- 
  
      INFO_MESSAGE("attempting DHCP RENEW");
--- 719,722 ----
Index: dhcp-client.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** dhcp-client.c	31 Dec 2002 10:30:59 -0000	1.20
--- dhcp-client.c	2 Jan 2003 04:23:01 -0000	1.21
***************
*** 166,174 ****
          interface_list = rawnet_list_inactive_interfaces();
  
!     if(interface_list == NULL)
          return NULL;
  
!     first_interface = xstrdup(interface_list->data);
!     purge_list(interface_list, NULL);
      return first_interface;
  }
--- 166,176 ----
          interface_list = rawnet_list_inactive_interfaces();
  
!     if(list_get_len(interface_list) == 0) {
!         list_destroy(interface_list, xfree);
          return NULL;
+     }
  
!     first_interface = xstrdup(list_first(interface_list));
!     list_destroy(interface_list, xfree);
      return first_interface;
  }
Index: dhcp-com.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** dhcp-com.c	27 Dec 2002 02:52:30 -0000	1.7
--- dhcp-com.c	2 Jan 2003 04:23:01 -0000	1.8
***************
*** 42,47 ****
  
      dhcp = xmalloc(sizeof(dhcp_obj));
!     dhcp->options = NULL;
!     dhcp->options_seek = NULL;
  
      return dhcp;
--- 42,46 ----
  
      dhcp = xmalloc(sizeof(dhcp_obj));
!     dhcp->options = list_create();
  
      return dhcp;
***************
*** 52,77 ****
  void dhcp_purge_option_list(list_t *options)
  {
-     list_t *list_ptr, *tmp;
-     dhcp_option_t *option;
- 
      /* Free up options. */
  
!     if(options) {
! 
!         list_ptr = options;
! 
!         while(list_ptr) {
! 
!             tmp = list_ptr->next;
!             option = list_ptr->data;
! 
!             xfree(option->data);
!             xfree(option);
!             xfree(list_ptr);
! 
!             list_ptr = tmp;
!         }
!     }
! 
      return;
  }
--- 51,57 ----
  void dhcp_purge_option_list(list_t *options)
  {
      /* Free up options. */
  
!     list_destroy(options, xfree);
      return;
  }
***************
*** 82,87 ****
  {
      dhcp_purge_option_list(dhcp->options);
!     dhcp->options = NULL;
!     dhcp->options_seek = NULL;
  
      return;
--- 62,66 ----
  {
      dhcp_purge_option_list(dhcp->options);
!     dhcp->options = list_create();
  
      return;
***************
*** 177,181 ****
              break;
  
!         dhcp->options = add_to_end_of_list(dhcp->options, option);
  
          len -= (optlen + 2);
--- 156,160 ----
              break;
  
!         list_add_to_end(dhcp->options, option);
  
          len -= (optlen + 2);
***************
*** 184,189 ****
      }
  
-     dhcp->options_seek = dhcp->options;
- 
      return;
  }
--- 163,166 ----
***************
*** 336,340 ****
  void dhcp_reset_option_seek(dhcp_obj * dhcp)
  {
!     dhcp->options_seek = dhcp->options;
  }
  
--- 313,317 ----
  void dhcp_reset_option_seek(dhcp_obj * dhcp)
  {
!     list_rewind(dhcp->options);
  }
  
***************
*** 343,356 ****
  dhcp_option_t *dhcp_get_next_option(dhcp_obj * dhcp)
  {
!     dhcp_option_t *rval;
! 
!     if(dhcp->options_seek == NULL)
!         return NULL;
! 
!     rval = dhcp->options_seek->data;
! 
!     dhcp->options_seek = dhcp->options_seek->next;
! 
!     return rval;
  }
  
--- 320,324 ----
  dhcp_option_t *dhcp_get_next_option(dhcp_obj * dhcp)
  {
!     return(list_next(dhcp->options));
  }
  
***************
*** 462,471 ****
  {
      uint16_t len = 0;
-     list_t *opts;
      dhcp_option_t *opt;
      int padding;
  
!     for(opts = options; opts; opts = opts->next) {
!         opt = opts->data;
  
          len += 2; /* for tag and len bytes. */
--- 430,438 ----
  {
      uint16_t len = 0;
      dhcp_option_t *opt;
      int padding;
  
!     list_rewind(options);
!     while((opt = list_next(options)) != NULL) {
  
          len += 2; /* for tag and len bytes. */
***************
*** 691,695 ****
  {
      dhcp->options = options;
-     dhcp->options_seek = options;
      return;
  }
--- 658,661 ----
Index: dhcp-conf.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** dhcp-conf.c	22 Dec 2002 08:31:29 -0000	1.8
--- dhcp-conf.c	2 Jan 2003 04:23:01 -0000	1.9
***************
*** 106,112 ****
  static void directive_destroy(directive_t *directive)
  {
!     list_t *type_ptr, *arg_ptr;
!     list_t *tmp;
!     arg_type_t arg_type;
  
      arg_ptr = directive->arguments;
--- 106,113 ----
  static void directive_destroy(directive_t *directive)
  {
!     list_t *arg_ptr;
!     list_t *type_ptr;
!     arg_type_t *arg_type;
!     void       *arg_data;
  
      arg_ptr = directive->arguments;
***************
*** 116,139 ****
       * and call the destroy routine per argument. */
  
!     while(type_ptr) {
!         
!         /* FIXME: one of the limitations of the list code we're
!          * using is that we cannot perform single purges.  fix
!          * later. just do raw list code here. */
  
!         arg_type = *(arg_type_t *)type_ptr->data;
  
!         argument_destroyers[arg_type](arg_ptr->data);
!         arg_type_destroy((arg_type_t *)type_ptr->data);
  
!         tmp = type_ptr->next;
!         xfree(type_ptr);
!         type_ptr = tmp;
  
-         tmp = arg_ptr->next;
-         xfree(arg_ptr);
-         arg_ptr  = tmp;
      }
  
      return;
  }
--- 117,143 ----
       * and call the destroy routine per argument. */
  
!     list_rewind(type_ptr);
!     list_rewind(arg_ptr);
!     while((arg_type = list_next(type_ptr)) != NULL) {
  
!         /* each arg_type tells us which destructor to call on the
!          * argument data. */
  
!         arg_data = list_next(arg_ptr);
  
!         /* we're automatically rewound after any removal. */
!         /* this won't free up the datums themselves. */
!         list_remove_by_datum(type_ptr, arg_type); 
!         list_remove_by_datum(arg_ptr,  arg_data);
! 
!         /* now destroy ourselves. */
!         argument_destroyers[*arg_type](arg_data);
!         arg_type_destroy((arg_type_t *)arg_type);
  
      }
  
+     list_destroy(type_ptr, NULL);
+     list_destroy(arg_ptr, NULL);
+ 
      return;
  }
***************
*** 159,163 ****
      conf->filename = xstrdup(filename);
      conf->commands = commands;
!     conf->directives = NULL;
  
      return conf;
--- 163,167 ----
      conf->filename = xstrdup(filename);
      conf->commands = commands;
!     conf->directives = list_create();
  
      return conf;
***************
*** 168,172 ****
      xfree(conf->filename);
      tokenizer_destroy(conf->tokenizer);
!     purge_list(conf->directives, directive_destroy_l);
      xfree(conf);
  
--- 172,176 ----
      xfree(conf->filename);
      tokenizer_destroy(conf->tokenizer);
!     list_destroy(conf->directives, directive_destroy_l);
      xfree(conf);
  
***************
*** 319,326 ****
  static void *compile_arg_string_list(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols)
  {
!     list_t *string_list = NULL;
      char *string;
      token_t token;
  
      /* ask compile_arg_string_list to do the work for us. 
       * we peek for commas but that's about it. */
--- 323,331 ----
  static void *compile_arg_string_list(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols)
  {
!     list_t *string_list;
      char *string;
      token_t token;
  
+     string_list = list_create();
      /* ask compile_arg_string_list to do the work for us. 
       * we peek for commas but that's about it. */
***************
*** 334,342 ****
  
              ERROR_MESSAGE("no string list found at %d\n", conf_get_line_no(conf));
!             purge_list(string_list, NULL);
              return NULL;
          }
  
!         string_list = add_to_end_of_list(string_list, string);
  
          /* now peek for a comma, if available keep going. */
--- 339,347 ----
  
              ERROR_MESSAGE("no string list found at %d\n", conf_get_line_no(conf));
!             list_destroy(string_list, xfree);
              return NULL;
          }
  
!         list_add_to_end(string_list, string);
  
          /* now peek for a comma, if available keep going. */
***************
*** 383,389 ****
  
          arg_type = arg_type_create(command->argument_types[i]);
!         directive->argument_types = add_to_end_of_list(directive->argument_types, arg_type);
! 
!         directive->arguments = add_to_end_of_list(directive->arguments, args);
      }
  
--- 388,393 ----
  
          arg_type = arg_type_create(command->argument_types[i]);
!         list_add_to_end(directive->argument_types, arg_type);
!         list_add_to_end(directive->arguments, args);
      }
  
***************
*** 437,441 ****
      token_t token;
      directive_t *directive;
!     list_t *directive_list = NULL;
  
      /* if we have a brace, go ahead and read in a command list. by compiling each command under it
--- 441,447 ----
      token_t token;
      directive_t *directive;
!     list_t *directive_list;
! 
!     directive_list = list_create();
  
      /* if we have a brace, go ahead and read in a command list. by compiling each command under it
***************
*** 465,474 ****
              goto error;
  
!         directive_list = add_to_end_of_list(directive_list, directive);
          
      }
  
   error:
!         purge_list(directive_list, directive_destroy_l);
          return NULL;
  }
--- 471,480 ----
              goto error;
  
!         list_add_to_end(directive_list, directive);
          
      }
  
   error:
!         list_destroy(directive_list, directive_destroy_l);
          return NULL;
  }
***************
*** 485,489 ****
      list_t *list = data;
  
!     purge_list(list, NULL); /* just free up a list of strings. */
  }
  
--- 491,495 ----
      list_t *list = data;
  
!     list_destroy(list, xfree); /* just free up a list of strings. */
  }
  
***************
*** 492,496 ****
      list_t *list = data;
  
!     purge_list(list, directive_destroy_l); /* free up a list of directives. */
  
      return;
--- 498,502 ----
      list_t *list = data;
  
!     list_destroy(list, directive_destroy_l); /* free up a list of directives. */
  
      return;
***************
*** 520,524 ****
              return CONF_ERROR; /* if we got a string it should match or error. */
  
!         conf->directives = add_to_end_of_list(conf->directives, directive);
  
      }
--- 526,530 ----
              return CONF_ERROR; /* if we got a string it should match or error. */
  
!         list_add_to_end(conf->directives, directive);
  
      }
Index: dhcp-convert.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** dhcp-convert.c	23 Dec 2002 00:51:24 -0000	1.7
--- dhcp-convert.c	2 Jan 2003 04:23:01 -0000	1.8
***************
*** 59,62 ****
--- 59,65 ----
   */
  
+ /* forward declaration of utility routines. */
+ static void purge_list_internal(void *list);
+ 
  option_convert_handler option_convert_handlers[] = {
      {NULL, NULL, NULL, NULL}
***************
*** 268,271 ****
--- 271,280 ----
  };
  
+ /* utility routine to destroy list. */
+ static void purge_list_internal(void *list)
+ {
+     list_destroy(list, xfree);
+ }
+ 
  /* Byte conversions useful for flags, and 1/0 values. */
  
***************
*** 393,396 ****
--- 402,407 ----
      char *cp, *tmp_string, *orig_string;;
  
+     addr_list = list_create();
+ 
      sb = stringbuffer_create();
      stringbuffer_append(sb, string);
***************
*** 407,411 ****
          *cp = 0;
          addr = string_to_addr(tmp_string);
!         addr_list = add_to_end_of_list(addr_list, addr);
          cp++;
  
--- 418,422 ----
          *cp = 0;
          addr = string_to_addr(tmp_string);
!         list_add_to_end(addr_list, addr);
          cp++;
  
***************
*** 417,421 ****
  
      xfree(orig_string);
!     return addr_list;
  }
  
--- 428,438 ----
  
      xfree(orig_string);
! 
!     if(list_get_len(addr_list) == 0) {
!         list_destroy(addr_list, NULL);
!         return NULL;
!     } else {
!         return addr_list;
!     }
  }
  
***************
*** 432,452 ****
  void *string_addr_list_to_network(const char *string, unsigned char *len_ret)
  {
-     list_t *ptr;
      list_t *addr_list = string_to_addr_list(string);
      int count = 0;
      uint32_t *data, *cp;
  
!     for(ptr = addr_list; ptr; ptr = ptr->next)
!         count++;
  
!     data = xmalloc(count * IP_ADDR_LEN);
      cp = data;
  
!     for(ptr = addr_list; ptr; ptr = ptr->next) {
!         memcpy(cp, ptr->data, IP_ADDR_LEN);
          cp++;
      }
  
!     purge_list(addr_list, NULL);
  
      *len_ret = (count * 4);
--- 449,470 ----
  void *string_addr_list_to_network(const char *string, unsigned char *len_ret)
  {
      list_t *addr_list = string_to_addr_list(string);
      int count = 0;
      uint32_t *data, *cp;
+     uint32_t *addr;
  
!     if(addr_list == NULL)
!         return NULL;
  
!     data = xmalloc(count * list_get_len(addr_list));
      cp = data;
  
!     list_rewind(addr_list);
!     while((addr = list_next(addr_list)) != NULL)  {
!         memcpy(cp, addr, IP_ADDR_LEN);
          cp++;
      }
  
!     list_destroy(addr_list, xfree);
  
      *len_ret = (count * 4);
***************
*** 737,745 ****
  void *string_to_uint16_list(const char *s)
  {
!     list_t *list_ptr = NULL;
      void *val;
      const char *cp;
      char *ptr;
  
      cp = s;
      while((ptr = strchr(cp, ';')) != NULL) {
--- 755,765 ----
  void *string_to_uint16_list(const char *s)
  {
!     list_t *list_ptr;
      void *val;
      const char *cp;
      char *ptr;
  
+     list_ptr = list_create();
+ 
      cp = s;
      while((ptr = strchr(cp, ';')) != NULL) {
***************
*** 749,753 ****
              break;
  
!         list_ptr = add_to_list(list_ptr, val);
  
          ptr++;
--- 769,773 ----
              break;
  
!         list_add(list_ptr, val);
  
          ptr++;
***************
*** 755,758 ****
--- 775,783 ----
              break;
          cp = ptr;
+     }
+ 
+     if(list_get_len(list_ptr) == 0) {
+         list_destroy(list_ptr, NULL);
+         return NULL;
      }
  
Index: dhcp-icmp-discovery.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-icmp-discovery.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** dhcp-icmp-discovery.c	16 Nov 2002 00:23:43 -0000	1.3
--- dhcp-icmp-discovery.c	2 Jan 2003 04:23:01 -0000	1.4
***************
*** 152,156 ****
  list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses, int sends)
  {
!     list_t *rtts = NULL;
      int *latency, *average_latency;
      int send_count, unreachable_count, highest_latency;
--- 152,156 ----
  list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses, int sends)
  {
!     list_t *rtts;
      int *latency, *average_latency;
      int send_count, unreachable_count, highest_latency;
***************
*** 158,161 ****
--- 158,163 ----
      eth_addr_t dest_mac;
  
+     rtts = list_create();
+ 
      /* Our algorithm works as such: send out an ICMP echo request
       * and wait for a reply. We count the total number of
***************
*** 166,173 ****
       * address. */
  
!     /* loop per address. */
!     for(; addresses; addresses = addresses->next) {
! 
!         host_addr = addresses->data;
  
          /* We need to arp for MAC address first. Call
--- 168,173 ----
       * address. */
  
!     list_rewind(addresses);
!     while((host_addr = list_next(addresses)) != NULL) {
  
          /* We need to arp for MAC address first. Call
***************
*** 241,245 ****
  
          xfree(latency); /* free our latency array. */
!         rtts = add_to_list(rtts, average_latency);
  
          /* we need to copy the host address so
--- 241,245 ----
  
          xfree(latency); /* free our latency array. */
!         list_add(rtts, average_latency);
  
          /* we need to copy the host address so
***************
*** 249,255 ****
          memcpy(host_addr_copy, host_addr, sizeof(ip_addr_t));
  
!         rtts = add_to_list(rtts, host_addr_copy);
      }
  
!     return rtts;
  }
--- 249,259 ----
          memcpy(host_addr_copy, host_addr, sizeof(ip_addr_t));
  
!         list_add(rtts, host_addr_copy);
      }
  
!     if(list_get_len(rtts) == 0) {
!         list_destroy(rtts, NULL);
!         return NULL;
!     } else 
!         return rtts;
  }
Index: dhcp-interface.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** dhcp-interface.c	29 Dec 2002 05:09:55 -0000	1.5
--- dhcp-interface.c	2 Jan 2003 04:23:01 -0000	1.6
***************
*** 209,213 ****
  
      interfaces = arg;
!     check = interfaces->data; /* first is always the routine to
                                   check routine. */
  
--- 209,213 ----
  
      interfaces = arg;
!     check = list_first(interfaces); /* first is always the routine to
                                   check routine. */
  
***************
*** 219,223 ****
      if(check(entry)) {
          intf_name = xstrdup(entry->intf_name);
!         interfaces = add_to_end_of_list(interfaces, intf_name);
      }
  
--- 219,223 ----
      if(check(entry)) {
          intf_name = xstrdup(entry->intf_name);
!         list_add_to_end(interfaces, intf_name);
      }
  
***************
*** 228,243 ****
  {
      intf_t *interfaces;
!     list_t *interface_list = NULL;
!     list_t *returned_list;
  
      /* add check as first datum. */
!     interface_list = add_to_end_of_list(interface_list, check);
  
      interfaces = intf_open();
      if(interfaces == NULL) {
!         xfree(interface_list); /* fixme: this isn't really
!                                 * good. we should have a way to destroy a list but not its
!                                 * datums if we want to. */
          intf_close(interfaces);
          ERROR_MESSAGE("could not obtain interface handle: %s", strerror(errno));
          return NULL;
--- 228,243 ----
  {
      intf_t *interfaces;
!     list_t *interface_list;
  
+     interface_list = list_create();
      /* add check as first datum. */
!     list_add(interface_list, check);
  
      interfaces = intf_open();
      if(interfaces == NULL) {
! 
!         list_destroy(interface_list, NULL);
          intf_close(interfaces);
+ 
          ERROR_MESSAGE("could not obtain interface handle: %s", strerror(errno));
          return NULL;
***************
*** 248,255 ****
      intf_close(interfaces);
  
!     returned_list = interface_list->next;
!     xfree(interface_list);
! 
!     return returned_list;
  }
  
--- 248,253 ----
      intf_close(interfaces);
  
!     list_remove_by_datum(interface_list, check); /* remove our check routine. */
!     return interface_list;
  }
  
Index: dhcp-librawnet.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** dhcp-librawnet.h	29 Dec 2002 05:09:55 -0000	1.8
--- dhcp-librawnet.h	2 Jan 2003 04:23:01 -0000	1.9
***************
*** 82,86 ****
      uint32_t magic_cookie;      /* Magic cookie. */
      list_t *options;            /* Option list. */
-     list_t *options_seek;       /* Seek pointer to option list. */
  } dhcp_obj;
  
--- 82,85 ----
Index: dhcp-libutil.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** dhcp-libutil.h	30 Dec 2002 00:45:03 -0000	1.22
--- dhcp-libutil.h	2 Jan 2003 04:23:01 -0000	1.23
***************
*** 46,53 ****
  /* native data structures. */
  
! /* list object. */
! typedef struct list {
!     struct list *next;
      void *data;
  } list_t;
  
--- 46,59 ----
  /* native data structures. */
  
! typedef struct node {
!     struct node *next;
      void *data;
+ } node_t;
+ 
+ typedef struct {
+     node_t *head;
+     node_t *tail;
+     node_t *seek;
+     int len;
  } list_t;
  
***************
*** 195,206 ****
  
  /* Linked List routines. */
! extern list_t *add_to_list(list_t *head, void *datum);
! extern list_t *add_to_end_of_list(list_t *head, void *datum);
! extern list_t *remove_from_list(list_t *head, void *datum);
! extern void purge_list(list_t *head, void (*purge_func) (void *d));
! extern void purge_list_internal(void *head);
! extern list_t *join_lists(list_t *first_list, list_t *second_list);
! extern list_t *list_find_datum_by(list_t *list, int (*find_func) (void *, void *), void *arg);
! extern list_t *sort_list(list_t *list, int (*compare) (void *, void *));
  
  /* stringbuffer. */
--- 201,217 ----
  
  /* Linked List routines. */
! extern list_t *list_create(void);
! extern void list_add(list_t *list, void *data);
! extern void list_add_to_end(list_t *list, void *data);
! extern int list_remove_by_datum(list_t *list, void *data);
! extern void list_destroy(list_t *list, void (*purge_func) (void *d));
! extern void list_join(list_t *first_list, list_t *second_list);
! extern list_t *list_sort(list_t *list, int (*compare) (void *, void *));
! extern void *list_get_by_index(list_t *list, int index);
! extern void *list_first(list_t *list);
! extern void *list_second(list_t *list);
! extern void list_rewind(list_t *list);
! extern void *list_next(list_t *list);
! extern int list_get_len(list_t *list);
  
  /* stringbuffer. */
Index: dhcp-list.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-list.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** dhcp-list.c	16 Nov 2002 00:23:43 -0000	1.4
--- dhcp-list.c	2 Jan 2003 04:23:01 -0000	1.5
***************
*** 27,169 ****
  #include "dhcp-libutil.h"
  
! list_t *add_to_list(list_t *head, void *datum)
  {
!     list_t *tmp;
  
!     tmp = xmalloc(sizeof(list_t));
!     tmp->data = datum;
!     tmp->next = head;
  
!     return tmp;
  }
  
! list_t *add_to_end_of_list(list_t *head, void *datum)
  {
!     list_t *tmp, *tmp2;
  
!     tmp = xmalloc(sizeof(list_t));
!     tmp->data = datum;
!     tmp->next = NULL;
  
!     if(head == NULL) {
!         return tmp;
!     } else {
!         for(tmp2 = head; tmp2->next; tmp2 = tmp2->next);
!         tmp2->next = tmp;
  
!         if(head == NULL)
!             return tmp;
!         else
!             return head;
      }
  }
  
! list_t *remove_from_list(list_t *head, void *datum)
  {
!     list_t *tmp, *tmp2;
  
!     if(head->data == datum) {
!         tmp = head->next;
!         xfree(head);
!         return tmp;
!     } else {
  
!         for(tmp = head; tmp->next; tmp = tmp->next) {
  
!             if(tmp->next->data == datum) {
!                 tmp2 = tmp->next;
!                 tmp->next = tmp->next->next;
!                 xfree(tmp2);
!                 return head;
!             }
!         }
      }
  
!     return NULL; /* this should never happen. */
  
! }
  
! /* for convert array. */
  
! void purge_list_internal(void *head)
! {
!     purge_list((list_t *)head, NULL);
  }
  
! void purge_list(list_t *head, void (*purge_func) (void *d))
  {
!     list_t *tmp;
  
!     while(head != NULL) {
!         tmp = head;
!         head = head->next;
  
          if(purge_func)
!             purge_func(tmp->data);
!         else
!             xfree(tmp->data);
  
!         xfree(tmp);
      }
  
      return;
  }
  
! list_t *join_lists(list_t *first_list, list_t *second_list)
  {
-     list_t *ptr;
  
!     if(first_list == NULL)
!         return second_list;
  
!     if(second_list == NULL)
!         return first_list;
  
!     for(ptr = first_list; ptr->next; ptr = ptr->next);
  
!     ptr->next = second_list;
  
!     return first_list;
! }
  
! list_t *list_find_datum_by(list_t *list, int (*find_func) (void *, void *), void *arg)
! {
!     list_t *ptr;
  
!     for(ptr = list; ptr; ptr = ptr->next) {
!         if(find_func(ptr, arg))
!             return ptr;
      }
  
-     return NULL;
  }
  
! /* we use a fairly dumb sorting algorithm. optimize later.  the
!  * real problem is we're using a list which sucks for these kinds
!  * of things :-) */
! list_t *sort_list(list_t *list, int (*compare) (void *, void *))
  {
!     list_t *new_list = NULL;
!     list_t *highest, *ptr;
  
      while(1) {
-         /* keep looping until list is NULL. */
-         highest = list;
  
!         if(list == NULL)
              break;
  
!         /* otherwise move down list and compare values. */
!         for(ptr = list->next; ptr; ptr = ptr->next) {
!             if(compare(highest->data, ptr->data) == -1) {
!                 highest = ptr;
              }
          }
  
!         new_list = add_to_list(new_list, highest->data);
!         list = remove_from_list(list, highest->data);
! 
      }
  
      return new_list;
  }
--- 27,305 ----
  #include "dhcp-libutil.h"
  
! /* create a new list. */
! list_t *list_create(void)
  {
!     list_t *list;
  
!     list = xcalloc(sizeof(list_t));
  
!     return list;
  }
  
! /* add an item to the list. */
! void list_add(list_t *list, void *data)
  {
!     node_t *node;
  
!     node = xcalloc(sizeof(node_t));
!     node->next = list->head;
!     node->data = data;
  
!     /* if there are no other datums the tail should be the node
!      * too */
  
!     if(list->len == 0)
!         list->tail = node;
! 
!     list->head = node; /* make the head the new node. */
!     list->len++;       /* increment count. */
! 
!     /* automatic rewind here. */
!     list_rewind(list);
!     return;
! }
! 
! /* add an item to the end of the list. */
! void list_add_to_end(list_t *list, void *data)
! {        
!     node_t *node;
! 
!     /* if it's the only item in the list just add it normally. */
!     if(list->len == 0) {
!         list_add(list, data);
!         return;
      }
+ 
+     node = xcalloc(sizeof(node_t));
+     node->data = data;
+ 
+     list->tail->next = node;
+     list->tail  = node;
+ 
+     list->len++;
+ 
+     /* automatic rewind here. */
+     list_rewind(list);
+     return;
  }
  
! /* remove a list pointer by the datum. this does not free the
!  * datum itself. */
! int list_remove_by_datum(list_t *list, void *data)
  {
!     node_t *node, *node_prev;
  
!     if(list->len == 0) /* nothing to remove. */
!         return 1;
  
!     /* check if the datum is the head of the list. */
!     if(list->head->data == data)  { 
!         
!         /* just remove head. */
!         node = list->head;
!         list->head = list->head->next;
  
!         xfree(node);
! 
!         if(list->len == 1) /* then we should clear tail as well. */
!             list->tail = list->head;
! 
!         list->len--;
! 
!         /* automatic rewind here. */
!         list_rewind(list);
!         return 0;
      }
  
!     /* anything else means it's not the head and it's something further down. */
  
!     if(list->len == 1)
!         return 1; /* can't be anything else then */
  
!     node_prev = list->head;
!     for(node  = list->head->next; node; node = node->next) {
  
!         if(node->data == data) {
!             node_prev->next = node->next;
! 
!             /* if we're pruning the last item then set previous to the tail. */
!             if(list->tail == node)
!                 list->tail = node_prev;
! 
!             xfree(node);
!             list->len--;
! 
!             /* automatic rewind here. */
!             list_rewind(list);
!             return 0;
!         }
! 
!         node_prev = node;
!     }
! 
!     /* we did not find it. */
!     return 1;
  }
  
! /* destroy a list. use purge_func to freeing the datum if it is set. */
! void list_destroy(list_t *list, void (*purge_func) (void *d))
  {
!     node_t *node, *node_next;
  
!     if(list->len == 0)  {
!         /* nada, just destroy the list. */
!         xfree(list);
!         return;
!     }
! 
!     node = list->head;
!     while(1) {
!         node_next = node->next;
  
          if(purge_func)
!             purge_func(node->data);
  
!         xfree(node);
! 
!         node = node_next;
!         if(node == NULL)
!             break;
      }
  
+     xfree(list);
+ 
      return;
  }
  
! /* concatenate second list to first list. second_list's data is
!  * preserved but the list pointer itself is destroyed. */
! void list_join(list_t *first_list, list_t *second_list)
  {
  
!     if(second_list->len == 0) {
!         xfree(second_list);
  
!         /* automatic rewind here. */
!         list_rewind(first_list);
!         return;
  
!     } if(first_list->len == 0) {
  
!         first_list->len = second_list->len;
!         first_list->head = second_list->head;
!         first_list->tail = second_list->tail;
  
!         xfree(second_list);
  
!         /* automatic rewind here. */
!         list_rewind(first_list);
!         return;
  
!     } else {
! 
!         first_list->len += second_list->len;
!         first_list->tail->next = second_list->head;
!         first_list->tail = second_list->tail;
! 
!         xfree(second_list);
! 
!         /* automatic rewind here. */
!         list_rewind(first_list);
!         return;
      }
  
  }
  
! /* we use a fairly dumb sorting algorithm. we recreate a list
!  * and add the datums into it. once done just free up the old list
!  * without freeing the datums and return the new sorted list. */
! list_t *list_sort(list_t *list, int (*compare) (void *, void *))
  {
!     node_t *node_walk, *node_highest;
!     list_t *new_list;
! 
!     if(list->len <= 1) /* one or less means we cannot sort. */
!         return list;
! 
!     new_list = list_create();
  
      while(1) {
  
!         if(list->len == 1) {
!             list_add_to_end(new_list, list->head->data);
!             list_remove_by_datum(list, list->head->data);
              break;
+         }
  
!         node_highest = list->head;
!         for(node_walk = list->head->next; node_walk; node_walk = node_walk->next) {
!             if(compare(node_highest->data, node_walk->data) == 1) {
!                 node_highest = node_walk;
              }
          }
  
!         list_add_to_end(new_list, node_highest->data);
!         list_remove_by_datum(list, node_highest->data);
      }
  
+     list_destroy(list, NULL);
      return new_list;
+ }
+ 
+ void *list_get_by_index(list_t *list, int index)
+ {
+     int i;
+     node_t *node;
+ 
+     if(list->len == 0)
+         return NULL;
+ 
+     if((list->len -1) < index)
+         return NULL;
+ 
+     i = 0;
+     for(node = list->head; node && i < index; node = node->next) {
+         i++;
+     }
+ 
+     if(node == NULL)
+         return NULL;
+ 
+     return node->data;
+ }
+ 
+ /* useful routines for pairs. */
+ void *list_first(list_t *list)
+ {
+     return list_get_by_index(list, 0);
+ }
+ 
+ void *list_second(list_t *list)
+ {
+     return list_get_by_index(list, 1);
+ }
+ 
+ /* useful for walking a list. */
+ void list_rewind(list_t *list)
+ {
+     list->seek = list->head;
+     return;
+ }
+ 
+ void *list_next(list_t *list)
+ {
+     void *data;
+ 
+     if(list->seek == NULL)
+         return NULL;
+ 
+     data = list->seek->data;
+     list->seek = list->seek->next;
+ 
+     return data;
+ }
+ 
+ int list_get_len(list_t *list)
+ {
+     return list->len;
  }
Index: dhcp-sniff.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sniff.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** dhcp-sniff.c	29 Dec 2002 05:09:55 -0000	1.5
--- dhcp-sniff.c	2 Jan 2003 04:23:01 -0000	1.6
***************
*** 90,95 ****
          if(available_interfaces != NULL) {
  
!             interface_name = xstrdup(available_interfaces->data);
!             purge_list(available_interfaces, NULL);
  
          } else {
--- 90,95 ----
          if(available_interfaces != NULL) {
  
!             interface_name = xstrdup(list_first(available_interfaces));
!             list_destroy(available_interfaces, xfree);
  
          } else {
Index: dhcp-sysconf.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** dhcp-sysconf.c	29 Dec 2002 05:09:55 -0000	1.11
--- dhcp-sysconf.c	2 Jan 2003 04:23:01 -0000	1.12
***************
*** 244,252 ****
  {
      struct route_entry r_entry;
!     uint32_t *addr_val = NULL;
      route_t *rt;
      list_t *routers;
!     list_t *average_latencies, *list_ptr;
!     int lowest_latency;
      int *latency;
      int sends;
--- 244,252 ----
  {
      struct route_entry r_entry;
!     uint32_t *tmp_addr_val, *addr_val = NULL;
      route_t *rt;
      list_t *routers;
!     list_t *average_latencies;
!     int *lowest_latency;
      int *latency;
      int sends;
***************
*** 257,260 ****
--- 257,261 ----
      sends = client_conf_get_icmp_retries(dc->conf);
  
+     /* we're guaranteed at least one router and one returned from icmp_rtt_discovery */
      routers = value;
      average_latencies = icmp_rtt_discovery(dc->rawnet, routers, sends);
***************
*** 263,276 ****
       * we still want to use one of them.
       * (See RFC 1812, section 4.3.3.6.) */
-     addr_val = average_latencies->data;
-     lowest_latency = *(int *)average_latencies->next->data;
  
!     /* Now pick best router and use it as default. */
!     for(list_ptr = average_latencies; list_ptr != NULL; list_ptr = list_ptr->next->next) {
  
!         latency = list_ptr->next->data;
!         if(*latency != -1 && *latency < lowest_latency) {
!             lowest_latency = *latency;
!             addr_val = list_ptr->next->data;
          }
      }
--- 264,278 ----
       * we still want to use one of them.
       * (See RFC 1812, section 4.3.3.6.) */
  
!     list_rewind(average_latencies);
!     addr_val = list_next(average_latencies);
!     lowest_latency = list_next(average_latencies);
  
!     while(((tmp_addr_val = list_next(average_latencies)) != NULL)
!           && ((latency = list_next(average_latencies)) != NULL)) {
! 
!         if(*latency != -1 && *latency < *lowest_latency) {
!             *lowest_latency = *latency;
!             addr_val = tmp_addr_val;
          }
      }
***************
*** 284,288 ****
      memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN);
  
!     purge_list(average_latencies, NULL);
  
      rt = route_open();
--- 286,290 ----
      memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN);
  
!     list_destroy(average_latencies, xfree);
  
      rt = route_open();
***************
*** 332,337 ****
  {
      FILE *fp;
!     list_t *servers;
      struct in_addr addr;
  
      fp = file_open_or_create_safe("resolv.conf", "a");
--- 334,340 ----
  {
      FILE *fp;
!     list_t *servers = value;
      struct in_addr addr;
+     void *data;
  
      fp = file_open_or_create_safe("resolv.conf", "a");
***************
*** 339,344 ****
          return -1;
  
!     for(servers = value; servers; servers = servers->next) {
!         memcpy(&addr.s_addr, servers->data, IP_ADDR_LEN);
          fprintf(fp, "nameserver %s\n", inet_ntoa(addr));
      }
--- 342,348 ----
          return -1;
  
!     list_rewind(servers);
!     while((data = list_next(servers)) != NULL) {
!         memcpy(&addr.s_addr, data, IP_ADDR_LEN);
          fprintf(fp, "nameserver %s\n", inet_ntoa(addr));
      }
***************
*** 375,379 ****
  static int sysconf_setup_interface(list_t *options, dhcp_client_control_t *dc)
  {
-     list_t *list_ptr;
      uint32_t addr, netmask;
      uint8_t have_addr = 0;
--- 379,382 ----
***************
*** 385,391 ****
      INFO_MESSAGE("configuring interface: %s", dc->interface);
  
!     for(list_ptr = options; list_ptr; list_ptr = list_ptr->next) {
! 
!         ce = list_ptr->data;
  
          if(TAG_DHCP_REQUESTED_IP_ADDRESS == ce->tag) {
--- 388,393 ----
      INFO_MESSAGE("configuring interface: %s", dc->interface)...
 
[truncated message content] |