diff options
Diffstat (limited to 'plugins-root/check_dhcp.c')
-rw-r--r-- | plugins-root/check_dhcp.c | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index b874c555..88b7ca10 100644 --- a/plugins-root/check_dhcp.c +++ b/plugins-root/check_dhcp.c | |||
@@ -229,7 +229,7 @@ struct in_addr requested_address; | |||
229 | 229 | ||
230 | int process_arguments(int, char **); | 230 | int process_arguments(int, char **); |
231 | int call_getopt(int, char **); | 231 | int call_getopt(int, char **); |
232 | int validate_arguments(void); | 232 | int validate_arguments(int, int); |
233 | void print_usage(void); | 233 | void print_usage(void); |
234 | void print_help(void); | 234 | void print_help(void); |
235 | 235 | ||
@@ -463,10 +463,9 @@ int send_dhcp_discover(int sock){ | |||
463 | discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; | 463 | discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; |
464 | 464 | ||
465 | /* | 465 | /* |
466 | * transaction ID is supposed to be random. We won't use the address so | 466 | * transaction ID is supposed to be random. |
467 | * we don't care about high entropy here. time(2) is good enough. | ||
468 | */ | 467 | */ |
469 | srand(time(NULL)); | 468 | srand(time(NULL)^getpid()); |
470 | packet_xid=random(); | 469 | packet_xid=random(); |
471 | discover_packet.xid=htonl(packet_xid); | 470 | discover_packet.xid=htonl(packet_xid); |
472 | 471 | ||
@@ -692,17 +691,11 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st | |||
692 | } | 691 | } |
693 | 692 | ||
694 | else{ | 693 | else{ |
695 | |||
696 | /* why do we need to peek first? i don't know, its a hack. without it, the source address of the first packet received was | ||
697 | not being interpreted correctly. sigh... */ | ||
698 | bzero(&source_address,sizeof(source_address)); | 694 | bzero(&source_address,sizeof(source_address)); |
699 | address_size=sizeof(source_address); | 695 | address_size=sizeof(source_address); |
700 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size); | 696 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size); |
701 | if(verbose) | 697 | if(verbose) |
702 | printf("recv_result_1: %d\n",recv_result); | 698 | printf("recv_result: %d\n",recv_result); |
703 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size); | ||
704 | if(verbose) | ||
705 | printf("recv_result_2: %d\n",recv_result); | ||
706 | 699 | ||
707 | if(recv_result==-1){ | 700 | if(recv_result==-1){ |
708 | if(verbose){ | 701 | if(verbose){ |
@@ -1059,29 +1052,19 @@ int get_results(void){ | |||
1059 | 1052 | ||
1060 | /* process command-line arguments */ | 1053 | /* process command-line arguments */ |
1061 | int process_arguments(int argc, char **argv){ | 1054 | int process_arguments(int argc, char **argv){ |
1062 | int c; | 1055 | int arg_index; |
1063 | 1056 | ||
1064 | if(argc<1) | 1057 | if(argc<1) |
1065 | return ERROR; | 1058 | return ERROR; |
1066 | 1059 | ||
1067 | c=0; | 1060 | arg_index = call_getopt(argc,argv); |
1068 | while((c+=(call_getopt(argc-c,&argv[c])))<argc){ | 1061 | return validate_arguments(argc,arg_index); |
1069 | |||
1070 | /* | ||
1071 | if(is_option(argv[c])) | ||
1072 | continue; | ||
1073 | */ | ||
1074 | } | ||
1075 | |||
1076 | return validate_arguments(); | ||
1077 | } | 1062 | } |
1078 | 1063 | ||
1079 | 1064 | ||
1080 | 1065 | ||
1081 | int call_getopt(int argc, char **argv){ | 1066 | int call_getopt(int argc, char **argv){ |
1082 | int c=0; | 1067 | extern int optind; |
1083 | int i=0; | ||
1084 | |||
1085 | int option_index = 0; | 1068 | int option_index = 0; |
1086 | static struct option long_options[] = | 1069 | static struct option long_options[] = |
1087 | { | 1070 | { |
@@ -1098,25 +1081,14 @@ int call_getopt(int argc, char **argv){ | |||
1098 | }; | 1081 | }; |
1099 | 1082 | ||
1100 | while(1){ | 1083 | while(1){ |
1101 | c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); | 1084 | int c=0; |
1102 | 1085 | ||
1103 | i++; | 1086 | c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); |
1104 | 1087 | ||
1105 | if(c==-1||c==EOF||c==1) | 1088 | if(c==-1||c==EOF||c==1) |
1106 | break; | 1089 | break; |
1107 | 1090 | ||
1108 | switch(c){ | 1091 | switch(c){ |
1109 | case 'w': | ||
1110 | case 'r': | ||
1111 | case 't': | ||
1112 | case 'i': | ||
1113 | i++; | ||
1114 | break; | ||
1115 | default: | ||
1116 | break; | ||
1117 | } | ||
1118 | |||
1119 | switch(c){ | ||
1120 | 1092 | ||
1121 | case 's': /* DHCP server address */ | 1093 | case 's': /* DHCP server address */ |
1122 | resolve_host(optarg,&dhcp_ip); | 1094 | resolve_host(optarg,&dhcp_ip); |
@@ -1163,11 +1135,11 @@ int call_getopt(int argc, char **argv){ | |||
1163 | 1135 | ||
1164 | case 'V': /* version */ | 1136 | case 'V': /* version */ |
1165 | print_revision(progname, NP_VERSION); | 1137 | print_revision(progname, NP_VERSION); |
1166 | exit(STATE_OK); | 1138 | exit(STATE_UNKNOWN); |
1167 | 1139 | ||
1168 | case 'h': /* help */ | 1140 | case 'h': /* help */ |
1169 | print_help(); | 1141 | print_help(); |
1170 | exit(STATE_OK); | 1142 | exit(STATE_UNKNOWN); |
1171 | 1143 | ||
1172 | case 'v': /* verbose */ | 1144 | case 'v': /* verbose */ |
1173 | verbose=1; | 1145 | verbose=1; |
@@ -1181,12 +1153,14 @@ int call_getopt(int argc, char **argv){ | |||
1181 | break; | 1153 | break; |
1182 | } | 1154 | } |
1183 | } | 1155 | } |
1184 | 1156 | return optind; | |
1185 | return i; | ||
1186 | } | 1157 | } |
1187 | 1158 | ||
1188 | 1159 | ||
1189 | int validate_arguments(void){ | 1160 | int validate_arguments(int argc, int arg_index){ |
1161 | |||
1162 | if(argc-optind > 0) | ||
1163 | usage(_("Got unexpected non-option argument")); | ||
1190 | 1164 | ||
1191 | return OK; | 1165 | return OK; |
1192 | } | 1166 | } |