diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_udp.c | 93 |
1 files changed, 26 insertions, 67 deletions
diff --git a/plugins/check_udp.c b/plugins/check_udp.c index d00ce9c..f6b528d 100644 --- a/plugins/check_udp.c +++ b/plugins/check_udp.c | |||
@@ -49,7 +49,6 @@ int critical_time = 0; | |||
49 | int check_critical_time = FALSE; | 49 | int check_critical_time = FALSE; |
50 | 50 | ||
51 | int process_arguments (int, char **); | 51 | int process_arguments (int, char **); |
52 | int call_getopt (int, char **); | ||
53 | void print_usage (void); | 52 | void print_usage (void); |
54 | void print_help (void); | 53 | void print_help (void); |
55 | 54 | ||
@@ -57,7 +56,7 @@ int verbose = FALSE; | |||
57 | int server_port = 0; | 56 | int server_port = 0; |
58 | char *server_address = NULL; | 57 | char *server_address = NULL; |
59 | char *server_expect = NULL; | 58 | char *server_expect = NULL; |
60 | char *server_send = NULL; | 59 | char *server_send = ""; |
61 | 60 | ||
62 | int | 61 | int |
63 | main (int argc, char **argv) | 62 | main (int argc, char **argv) |
@@ -126,51 +125,6 @@ process_arguments (int argc, char **argv) | |||
126 | { | 125 | { |
127 | int c; | 126 | int c; |
128 | 127 | ||
129 | if (argc < 2) | ||
130 | usage ("\n"); | ||
131 | |||
132 | for (c = 1; c < argc; c++) { | ||
133 | if (strcmp ("-to", argv[c]) == 0) | ||
134 | strcpy (argv[c], "-t"); | ||
135 | else if (strcmp ("-wt", argv[c]) == 0) | ||
136 | strcpy (argv[c], "-w"); | ||
137 | else if (strcmp ("-ct", argv[c]) == 0) | ||
138 | strcpy (argv[c], "-c"); | ||
139 | } | ||
140 | |||
141 | c = 0; | ||
142 | while ((c += call_getopt (argc - c, &argv[c])) < argc) { | ||
143 | |||
144 | if (is_option (argv[c])) | ||
145 | continue; | ||
146 | |||
147 | if (server_address == NULL) { | ||
148 | if (argc > c) { | ||
149 | if (is_host (argv[c]) == FALSE) | ||
150 | usage ("Invalid host name/address\n"); | ||
151 | server_address = argv[c]; | ||
152 | } | ||
153 | else { | ||
154 | usage ("Host name was not supplied\n"); | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | |||
159 | if (server_send == NULL) | ||
160 | server_send = strscpy (server_send, ""); | ||
161 | |||
162 | return OK; | ||
163 | } | ||
164 | |||
165 | |||
166 | |||
167 | |||
168 | |||
169 | int | ||
170 | call_getopt (int argc, char **argv) | ||
171 | { | ||
172 | int c, i = 0; | ||
173 | |||
174 | #ifdef HAVE_GETOPT_H | 128 | #ifdef HAVE_GETOPT_H |
175 | int option_index = 0; | 129 | int option_index = 0; |
176 | static struct option long_options[] = { | 130 | static struct option long_options[] = { |
@@ -188,31 +142,25 @@ call_getopt (int argc, char **argv) | |||
188 | }; | 142 | }; |
189 | #endif | 143 | #endif |
190 | 144 | ||
145 | if (argc < 2) | ||
146 | usage ("\n"); | ||
147 | |||
148 | for (c = 1; c < argc; c++) { | ||
149 | if (strcmp ("-to", argv[c]) == 0) | ||
150 | strcpy (argv[c], "-t"); | ||
151 | else if (strcmp ("-wt", argv[c]) == 0) | ||
152 | strcpy (argv[c], "-w"); | ||
153 | else if (strcmp ("-ct", argv[c]) == 0) | ||
154 | strcpy (argv[c], "-c"); | ||
155 | } | ||
156 | |||
191 | while (1) { | 157 | while (1) { |
192 | #ifdef HAVE_GETOPT_H | 158 | #ifdef HAVE_GETOPT_H |
193 | c = | 159 | c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, &option_index); |
194 | getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, | ||
195 | &option_index); | ||
196 | #else | 160 | #else |
197 | c = getopt (argc, argv, "+hVvH:e:s:c:w:t:p:"); | 161 | c = getopt (argc, argv, "+hVvH:e:s:c:w:t:p:"); |
198 | #endif | 162 | #endif |
199 | 163 | ||
200 | i++; | ||
201 | |||
202 | if (c == -1 || c == EOF || c == 1) | ||
203 | break; | ||
204 | |||
205 | switch (c) { | ||
206 | case 'H': | ||
207 | case 'c': | ||
208 | case 'w': | ||
209 | case 't': | ||
210 | case 'p': | ||
211 | case 'e': | ||
212 | case 's': | ||
213 | i++; | ||
214 | } | ||
215 | |||
216 | switch (c) { | 164 | switch (c) { |
217 | case '?': /* print short usage statement if args not parsable */ | 165 | case '?': /* print short usage statement if args not parsable */ |
218 | printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); | 166 | printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); |
@@ -262,7 +210,18 @@ call_getopt (int argc, char **argv) | |||
262 | break; | 210 | break; |
263 | } | 211 | } |
264 | } | 212 | } |
265 | return i; | 213 | |
214 | c = optind; | ||
215 | if (server_address == NULL && argv[c]) { | ||
216 | if (is_host (argv[c]) == FALSE) | ||
217 | usage ("Invalid host name/address\n"); | ||
218 | server_address = argv[c++]; | ||
219 | } | ||
220 | else { | ||
221 | usage ("Host name was not supplied\n"); | ||
222 | } | ||
223 | |||
224 | return c; | ||
266 | } | 225 | } |
267 | 226 | ||
268 | 227 | ||