summaryrefslogtreecommitdiffstats
path: root/plugins/check_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_udp.c')
-rw-r--r--plugins/check_udp.c93
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;
49int check_critical_time = FALSE; 49int check_critical_time = FALSE;
50 50
51int process_arguments (int, char **); 51int process_arguments (int, char **);
52int call_getopt (int, char **);
53void print_usage (void); 52void print_usage (void);
54void print_help (void); 53void print_help (void);
55 54
@@ -57,7 +56,7 @@ int verbose = FALSE;
57int server_port = 0; 56int server_port = 0;
58char *server_address = NULL; 57char *server_address = NULL;
59char *server_expect = NULL; 58char *server_expect = NULL;
60char *server_send = NULL; 59char *server_send = "";
61 60
62int 61int
63main (int argc, char **argv) 62main (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
169int
170call_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