[Dhcp-agent-commits] CVS: dhcp-agent dhcp-agent.h,1.52,1.53 dhcp-interface.c,1.15,1.16
Status: Alpha
Brought to you by:
actmodern
From: Thamer Al-H. <act...@us...> - 2002-06-08 17:35:05
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv8029 Modified Files: dhcp-agent.h dhcp-interface.c Log Message: added routine to dhcp-interface.c to return list of ethernet interfaces which are either not up or do not have an address assigned; Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** dhcp-agent.h 8 Jun 2002 06:00:29 -0000 1.52 --- dhcp-agent.h 8 Jun 2002 17:35:02 -0000 1.53 *************** *** 820,823 **** --- 820,824 ---- extern void destroy_interface_control(interface_control_t *ic); extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); + extern list_t *interface_get_available(void); /* client states */ Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-interface.c 6 Jun 2002 23:59:00 -0000 1.15 --- dhcp-interface.c 8 Jun 2002 17:35:02 -0000 1.16 *************** *** 142,143 **** --- 142,202 ---- return 0; } + + /* utility to get interface list and place it in a list. */ + + static int list_available_interfaces(const struct intf_entry *entry, void *arg) + { + list_t **p_list; /* pointer to linked list. */ + list_t *head; /* head of linked list. */ + char *intf_name = NULL; + + p_list = arg; + head = *p_list; + + /* + * Check the interface type is ethernet, + * is down OR has no IP address assigned to it. + * If it passes then add the name to the list. + */ + + if(entry->intf_type == INTF_TYPE_ETH) { + + if(((entry->intf_flags&INTF_FLAG_UP) == 0) /* true if not up. */ + || (entry->intf_addr.addr_type == ADDR_TYPE_NONE)) /* or true if no address + set. */ + intf_name = strdup(entry->intf_name); + } + + if(intf_name != NULL) + head = add_to_end_of_list(head, intf_name); + + *p_list = head; + + return 0; + } + + list_t *interface_get_available(void) + { + intf_t *interfaces; + list_t *interface_list; + list_t **p_list = xmalloc(sizeof(list_t *)); + *p_list = NULL; + + interfaces = intf_open(); + if(interfaces == NULL) { + + error_message("dhcp-interface: interfaces_get_available: could not obtain interface handle: %s\n", strerror(errno)); /* yes it's too long -- need exception stack. */ + + xfree(p_list); + intf_close(interfaces); + return NULL; + } + + intf_loop(interfaces, list_available_interfaces, p_list); + + interface_list = *p_list; + xfree(p_list); + intf_close(interfaces); + + return interface_list; + } |