Updated with more tests re: multiple status codes (Sven Nierlein)
[monitoring-plugins.git] / lib / utils_tcp.c
blob58d50b6a7379c5a1abc2fa941f6cbc7b811095d0
1 /*****************************************************************************
2 *
3 * Library for check_tcp
4 *
5 * License: GPL
6 * Copyright (c) 1999-2007 Nagios Plugins Development Team
7 *
8 * Last Modified: $Date$
9 *
10 * Description:
12 * This file contains utilities for check_tcp. These are tested by libtap
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * $Id$
30 *****************************************************************************/
32 #include "common.h"
33 #include "utils_tcp.h"
35 int
36 np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose)
38 int match = 0;
39 int i;
40 for (i = 0; i < expect_count; i++) {
41 if (verbose)
42 printf ("looking for [%s] %s [%s]\n", server_expect[i],
43 (exact_match) ? "in beginning of" : "anywhere in",
44 status);
46 if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
47 (! exact_match && strstr(status, server_expect[i])))
49 if(verbose) puts("found it");
50 match += 1;
51 } else
52 if(verbose) puts("couldn't find it");
54 if ((all == TRUE && match == expect_count) ||
55 (! all && match >= 1)) {
56 return TRUE;
57 } else
58 return FALSE;