summaryrefslogtreecommitdiffstats
path: root/plugins-root/check_dhcp.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2015-10-02 12:18:13 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2015-10-02 12:18:13 +0200
commit466cb79e5224327c29fc6b84a1cec99c2b190c5a (patch)
treebd90a0aa674018a56016010038e79ffb89b462d8 /plugins-root/check_dhcp.c
parent6a939fa1bacd90b64a8e09939ee06223330f7567 (diff)
downloadmonitoring-plugins-466cb79e5224327c29fc6b84a1cec99c2b190c5a.tar.gz
check_dhcp: Fix option parsing
The call_getopt() function didn't always return the correct number of processed arguments. However, since check_dhcp doesn't support non-option arguments, the caller doesn't need this number anyway. Closes #1345.
Diffstat (limited to 'plugins-root/check_dhcp.c')
-rw-r--r--plugins-root/check_dhcp.c43
1 files changed, 12 insertions, 31 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index 5508d5f9..25d4ed40 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -229,7 +229,7 @@ struct in_addr requested_address;
229 229
230int process_arguments(int, char **); 230int process_arguments(int, char **);
231int call_getopt(int, char **); 231int call_getopt(int, char **);
232int validate_arguments(void); 232int validate_arguments(int, int);
233void print_usage(void); 233void print_usage(void);
234void print_help(void); 234void print_help(void);
235 235
@@ -1059,29 +1059,19 @@ int get_results(void){
1059 1059
1060/* process command-line arguments */ 1060/* process command-line arguments */
1061int process_arguments(int argc, char **argv){ 1061int process_arguments(int argc, char **argv){
1062 int c; 1062 int arg_index;
1063 1063
1064 if(argc<1) 1064 if(argc<1)
1065 return ERROR; 1065 return ERROR;
1066 1066
1067 c=0; 1067 arg_index = call_getopt(argc,argv);
1068 while((c+=(call_getopt(argc-c,&argv[c])))<argc){ 1068 return validate_arguments(argc,arg_index);
1069
1070 /*
1071 if(is_option(argv[c]))
1072 continue;
1073 */
1074 }
1075
1076 return validate_arguments();
1077 } 1069 }
1078 1070
1079 1071
1080 1072
1081int call_getopt(int argc, char **argv){ 1073int call_getopt(int argc, char **argv){
1082 int c=0; 1074 extern int optind;
1083 int i=0;
1084
1085 int option_index = 0; 1075 int option_index = 0;
1086 static struct option long_options[] = 1076 static struct option long_options[] =
1087 { 1077 {
@@ -1098,25 +1088,14 @@ int call_getopt(int argc, char **argv){
1098 }; 1088 };
1099 1089
1100 while(1){ 1090 while(1){
1101 c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index); 1091 int c=0;
1102 1092
1103 i++; 1093 c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index);
1104 1094
1105 if(c==-1||c==EOF||c==1) 1095 if(c==-1||c==EOF||c==1)
1106 break; 1096 break;
1107 1097
1108 switch(c){ 1098 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 1099
1121 case 's': /* DHCP server address */ 1100 case 's': /* DHCP server address */
1122 resolve_host(optarg,&dhcp_ip); 1101 resolve_host(optarg,&dhcp_ip);
@@ -1181,12 +1160,14 @@ int call_getopt(int argc, char **argv){
1181 break; 1160 break;
1182 } 1161 }
1183 } 1162 }
1184 1163 return optind;
1185 return i+1;
1186 } 1164 }
1187 1165
1188 1166
1189int validate_arguments(void){ 1167int validate_arguments(int argc, int arg_index){
1168
1169 if(argc-optind > 0)
1170 usage(_("Got unexpected non-option argument"));
1190 1171
1191 return OK; 1172 return OK;
1192 } 1173 }