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
|
--- check_dhcp.c.orig 2005-09-07 12:33:44.000000000 -0700
+++ check_dhcp.c 2005-09-07 15:35:26.000000000 -0700
@@ -157,6 +157,7 @@
typedef struct requested_server_struct{
struct in_addr server_address;
+ int answered;
struct requested_server_struct *next;
}requested_server;
@@ -479,6 +480,7 @@
int get_dhcp_offer(int sock){
dhcp_packet offer_packet;
struct sockaddr_in source;
+ struct sockaddr_in via;
int result=OK;
int timeout=1;
int responses=0;
@@ -499,6 +501,7 @@
printf("\n\n");
bzero(&source,sizeof(source));
+ bzero(&via,sizeof(via));
bzero(&offer_packet,sizeof(offer_packet));
result=OK;
@@ -516,9 +519,18 @@
responses++;
}
+ /* The "source" is either a server or a relay. */
+ /* Save a copy of "source" into "via" even if it's via itself */
+ memcpy(&via,&source,sizeof(source)) ;
+
+ /* If siaddr is non-zero, set "source" to siaddr */
+ if (offer_packet.siaddr.s_addr != 0L) {
+ source.sin_addr.s_addr = offer_packet.siaddr.s_addr ;
+ }
if (verbose) {
- printf(_("DHCPOFFER from IP address %s\n"),inet_ntoa(source.sin_addr));
+ printf(_("DHCPOFFER from IP address %s"),inet_ntoa(source.sin_addr));
+ printf(_(" via %s\n"),inet_ntoa(via.sin_addr));
printf("DHCPOFFER XID: %lu (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid));
}
@@ -727,6 +739,7 @@
return ERROR;
new_server->server_address=server_address;
+ new_server->answered=FALSE;
new_server->next=requested_server_list;
requested_server_list=new_server;
@@ -887,9 +900,17 @@
if(!memcmp(&temp_offer->server_address,&temp_server->server_address,sizeof(temp_server->server_address))){
if (verbose) {
printf(_("DHCP Server Match: Offerer=%s"),inet_ntoa(temp_offer->server_address));
- printf(_(" Requested=%s\n"),inet_ntoa(temp_server->server_address));
+ printf(_(" Requested=%s"),inet_ntoa(temp_server->server_address));
+ if (temp_server->answered)
+ printf(_(" (duplicate)"));
+
+ printf(_("\n"));
}
- requested_responses++;
+ if (temp_server->answered == FALSE){
+ requested_responses++;
+ temp_server->answered=TRUE;
+ }
+
}
}
}
|