diff options
Diffstat (limited to 'plugins-root/check_dhcp.c')
-rw-r--r-- | plugins-root/check_dhcp.c | 63 |
1 files changed, 19 insertions, 44 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index b874c555..ad673237 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 | ||
@@ -323,7 +323,8 @@ int get_hardware_address(int sock,char *interface_name){ | |||
323 | #elif defined(__bsd__) | 323 | #elif defined(__bsd__) |
324 | /* King 2004 see ACKNOWLEDGEMENTS */ | 324 | /* King 2004 see ACKNOWLEDGEMENTS */ |
325 | 325 | ||
326 | int mib[6], len; | 326 | size_t len; |
327 | int mib[6]; | ||
327 | char *buf; | 328 | char *buf; |
328 | unsigned char *ptr; | 329 | unsigned char *ptr; |
329 | struct if_msghdr *ifm; | 330 | struct if_msghdr *ifm; |
@@ -463,10 +464,9 @@ int send_dhcp_discover(int sock){ | |||
463 | discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; | 464 | discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; |
464 | 465 | ||
465 | /* | 466 | /* |
466 | * transaction ID is supposed to be random. We won't use the address so | 467 | * transaction ID is supposed to be random. |
467 | * we don't care about high entropy here. time(2) is good enough. | ||
468 | */ | 468 | */ |
469 | srand(time(NULL)); | 469 | srand(time(NULL)^getpid()); |
470 | packet_xid=random(); | 470 | packet_xid=random(); |
471 | discover_packet.xid=htonl(packet_xid); | 471 | discover_packet.xid=htonl(packet_xid); |
472 | 472 | ||
@@ -692,17 +692,11 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st | |||
692 | } | 692 | } |
693 | 693 | ||
694 | else{ | 694 | 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)); | 695 | bzero(&source_address,sizeof(source_address)); |
699 | address_size=sizeof(source_address); | 696 | address_size=sizeof(source_address); |
700 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size); | ||
701 | if(verbose) | ||
702 | printf("recv_result_1: %d\n",recv_result); | ||
703 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size); | 697 | recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size); |
704 | if(verbose) | 698 | if(verbose) |
705 | printf("recv_result_2: %d\n",recv_result); | 699 | printf("recv_result: %d\n",recv_result); |
706 | 700 | ||
707 | if(recv_result==-1){ | 701 | if(recv_result==-1){ |
708 | if(verbose){ | 702 | if(verbose){ |
@@ -1059,29 +1053,19 @@ int get_results(void){ | |||
1059 | 1053 | ||
1060 | /* process command-line arguments */ | 1054 | /* process command-line arguments */ |
1061 | int process_arguments(int argc, char **argv){ | 1055 | int process_arguments(int argc, char **argv){ |
1062 | int c; | 1056 | int arg_index; |
1063 | 1057 | ||
1064 | if(argc<1) | 1058 | if(argc<1) |
1065 | return ERROR; | 1059 | return ERROR; |
1066 | 1060 | ||
1067 | c=0; | 1061 | arg_index = call_getopt(argc,argv); |
1068 | while((c+=(call_getopt(argc-c,&argv[c])))<argc){ | 1062 | return validate_arguments(argc,arg_index); |
1069 | |||
1070 | /* | ||
1071 | if(is_option(argv[c])) | ||
1072 | continue; | ||
1073 | */ | ||
1074 | } | ||
1075 | |||
1076 | return validate_arguments(); | ||
1077 | } | 1063 | } |
1078 | 1064 | ||
1079 | 1065 | ||
1080 | 1066 | ||
1081 | int call_getopt(int argc, char **argv){ | 1067 | int call_getopt(int argc, char **argv){ |
1082 | int c=0; | 1068 | extern int optind; |
1083 | int i=0; | ||
1084 | |||
1085 | int option_index = 0; | 1069 | int option_index = 0; |
1086 | static struct option long_options[] = | 1070 | static struct option long_options[] = |
1087 | { | 1071 | { |
@@ -1098,25 +1082,14 @@ int call_getopt(int argc, char **argv){ | |||
1098 | }; | 1082 | }; |
1099 | 1083 | ||
1100 | while(1){ | 1084 | while(1){ |
1101 | c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); | 1085 | int c=0; |
1102 | 1086 | ||
1103 | i++; | 1087 | c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); |
1104 | 1088 | ||
1105 | if(c==-1||c==EOF||c==1) | 1089 | if(c==-1||c==EOF||c==1) |
1106 | break; | 1090 | break; |
1107 | 1091 | ||
1108 | switch(c){ | 1092 | 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 | 1093 | ||
1121 | case 's': /* DHCP server address */ | 1094 | case 's': /* DHCP server address */ |
1122 | resolve_host(optarg,&dhcp_ip); | 1095 | resolve_host(optarg,&dhcp_ip); |
@@ -1163,11 +1136,11 @@ int call_getopt(int argc, char **argv){ | |||
1163 | 1136 | ||
1164 | case 'V': /* version */ | 1137 | case 'V': /* version */ |
1165 | print_revision(progname, NP_VERSION); | 1138 | print_revision(progname, NP_VERSION); |
1166 | exit(STATE_OK); | 1139 | exit(STATE_UNKNOWN); |
1167 | 1140 | ||
1168 | case 'h': /* help */ | 1141 | case 'h': /* help */ |
1169 | print_help(); | 1142 | print_help(); |
1170 | exit(STATE_OK); | 1143 | exit(STATE_UNKNOWN); |
1171 | 1144 | ||
1172 | case 'v': /* verbose */ | 1145 | case 'v': /* verbose */ |
1173 | verbose=1; | 1146 | verbose=1; |
@@ -1181,12 +1154,14 @@ int call_getopt(int argc, char **argv){ | |||
1181 | break; | 1154 | break; |
1182 | } | 1155 | } |
1183 | } | 1156 | } |
1184 | 1157 | return optind; | |
1185 | return i; | ||
1186 | } | 1158 | } |
1187 | 1159 | ||
1188 | 1160 | ||
1189 | int validate_arguments(void){ | 1161 | int validate_arguments(int argc, int arg_index){ |
1162 | |||
1163 | if(argc-optind > 0) | ||
1164 | usage(_("Got unexpected non-option argument")); | ||
1190 | 1165 | ||
1191 | return OK; | 1166 | return OK; |
1192 | } | 1167 | } |