--- nagios-plugins-HEAD-200702121300/plugins-root/check_dhcp.c 2007-01-28 22:46:41.000000000 +0100 +++ nagios-plugins-HEAD-200702121300/plugins-root/check_dhcp.c 2007-02-23 22:36:30.200102288 +0100 @@ -182,6 +182,7 @@ typedef struct requested_server_struct{ #define DHCP_OPTION_BROADCAST_ADDRESS 28 #define DHCP_OPTION_REQUESTED_ADDRESS 50 #define DHCP_OPTION_LEASE_TIME 51 +#define DHCP_OPTION_SERVER_IDENTIFIER 54 #define DHCP_OPTION_RENEWAL_TIME 58 #define DHCP_OPTION_REBINDING_TIME 59 @@ -768,6 +769,7 @@ int add_dhcp_offer(struct in_addr source int y; unsigned option_type; unsigned option_length; + struct in_addr serv_ident = {0}; if(offer_packet==NULL) return ERROR; @@ -789,23 +791,27 @@ int add_dhcp_offer(struct in_addr source printf("Option: %d (0x%02X)\n",option_type,option_length); /* get option data */ - if(option_type==DHCP_OPTION_LEASE_TIME){ - memcpy(&dhcp_lease_time, &offer_packet->options[x],sizeof(dhcp_lease_time)); + switch(option_type) { + case DHCP_OPTION_LEASE_TIME: + memcpy(&dhcp_lease_time,offer_packet->options+x,sizeof dhcp_lease_time); dhcp_lease_time = ntohl(dhcp_lease_time); - } - if(option_type==DHCP_OPTION_RENEWAL_TIME){ - memcpy(&dhcp_renewal_time, &offer_packet->options[x],sizeof(dhcp_renewal_time)); + break; + case DHCP_OPTION_RENEWAL_TIME: + memcpy(&dhcp_renewal_time,offer_packet->options+x,sizeof dhcp_renewal_time); dhcp_renewal_time = ntohl(dhcp_renewal_time); - } - if(option_type==DHCP_OPTION_REBINDING_TIME){ - memcpy(&dhcp_rebinding_time, &offer_packet->options[x],sizeof(dhcp_rebinding_time)); + break; + case DHCP_OPTION_REBINDING_TIME: + memcpy(&dhcp_rebinding_time,offer_packet->options+x,sizeof dhcp_rebinding_time); dhcp_rebinding_time = ntohl(dhcp_rebinding_time); - } - + break; + case DHCP_OPTION_SERVER_IDENTIFIER: + memcpy(&serv_ident.s_addr,offer_packet->options+x,sizeof serv_ident.s_addr); + break; + } /* skip option data we're ignoring */ - else - for(y=0;yserver_address=source; + new_offer->server_address=serv_ident.s_addr?serv_ident:source; new_offer->offered_address=offer_packet->yiaddr; new_offer->lease_time=dhcp_lease_time; new_offer->renewal_time=dhcp_renewal_time; @@ -836,14 +842,14 @@ int add_dhcp_offer(struct in_addr source if(verbose){ printf(_("Added offer from server @ %s"),inet_ntoa(new_offer->server_address)); printf(_(" of IP address %s\n"),inet_ntoa(new_offer->offered_address)); - } + } /* add new offer to head of list */ new_offer->next=dhcp_offer_list; dhcp_offer_list=new_offer; return OK; - } +} /* frees memory allocated to DHCP OFFER list */