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