summaryrefslogtreecommitdiffstats
path: root/plugins/check_tcp.c
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2013-02-10 21:57:55 (GMT)
committerSven Nierlein <sven@nierlein.de>2013-02-10 22:09:49 (GMT)
commit5fce5ceaeb316a1701c49a9c966d60b602101ed9 (patch)
tree5a370106e96fc075ecfe7a36795cc9badf393006 /plugins/check_tcp.c
parentf4bbd88a9f91bfbfbe590b3252043392e7248988 (diff)
downloadmonitoring-plugins-5fce5ceaeb316a1701c49a9c966d60b602101ed9.tar.gz
check_tcp: don't ignore trailing options
"./check_tcp -6 -p 80 host" leads to an error: TCP CRITICAL - Invalid hostname, address or socket: 127.0.0.1 because 127.0.0.1 is the fallback host, the tailing hostname was ignored.
Diffstat (limited to 'plugins/check_tcp.c')
-rw-r--r--plugins/check_tcp.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index af3ae24..ce966c3 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -1,30 +1,30 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Nagios check_tcp plugin 3* Nagios check_tcp plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2008 Nagios Plugins Development Team 6* Copyright (c) 1999-2008 Nagios Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_tcp plugin 10* This file contains the check_tcp plugin
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* $Id$ 26* $Id$
27* 27*
28*****************************************************************************/ 28*****************************************************************************/
29 29
30/* progname "check_tcp" changes depending on symlink called */ 30/* progname "check_tcp" changes depending on symlink called */
@@ -61,6 +61,7 @@ static int PORT = 0;
61 61
62static int server_port = 0; 62static int server_port = 0;
63static char *server_address = NULL; 63static char *server_address = NULL;
64static int host_specified = FALSE;
64static char *server_send = NULL; 65static char *server_send = NULL;
65static char *server_quit = NULL; 66static char *server_quit = NULL;
66static char **server_expect; 67static char **server_expect;
@@ -462,6 +463,7 @@ process_arguments (int argc, char **argv)
462#endif 463#endif
463 break; 464 break;
464 case 'H': /* hostname */ 465 case 'H': /* hostname */
466 host_specified = TRUE;
465 server_address = optarg; 467 server_address = optarg;
466 break; 468 break;
467 case 'c': /* critical */ 469 case 'c': /* critical */
@@ -588,6 +590,10 @@ process_arguments (int argc, char **argv)
588 } 590 }
589 } 591 }
590 592
593 c = optind;
594 if(host_specified == FALSE && c < argc)
595 server_address = strdup (argv[c++]);
596
591 if (server_address == NULL) 597 if (server_address == NULL)
592 usage4 (_("You must provide a server address")); 598 usage4 (_("You must provide a server address"));
593 else if (server_address[0] != '/' && is_host (server_address) == FALSE) 599 else if (server_address[0] != '/' && is_host (server_address) == FALSE)
@@ -666,4 +672,3 @@ print_usage (void)
666 printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n"); 672 printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
667 printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n"); 673 printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n");
668} 674}
669