summaryrefslogtreecommitdiffstats
path: root/web/attachments/217472-check_dhcp.c.patch
blob: d9b69e0f3140f913389ee94ae10518b418b73d80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
--- 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;y<option_length;y++,x++);
-	        }
+		if(option_type!=DHCP_OPTION_REBINDING_TIME)
+			x+=option_length;
+	}
 
 	if(verbose){
 		if(dhcp_lease_time==DHCP_INFINITE_TIME)
@@ -819,14 +825,14 @@ int add_dhcp_offer(struct in_addr source
 		if(dhcp_rebinding_time==DHCP_INFINITE_TIME)
 			printf(_("Rebinding Time: Infinite\n"));
 		printf(_("Rebinding Time: %lu seconds\n"),(unsigned long)dhcp_rebinding_time);
-		}
+	}
 
 	new_offer=(dhcp_offer *)malloc(sizeof(dhcp_offer));
 
 	if(new_offer==NULL)
 		return ERROR;
 
-	new_offer->server_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 */