diff options
Diffstat (limited to 'lib/utils_tcp.c')
-rw-r--r-- | lib/utils_tcp.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c new file mode 100644 index 00000000..b7075197 --- /dev/null +++ b/lib/utils_tcp.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /**************************************************************************** | ||
2 | * Utils for check_tcp | ||
3 | * | ||
4 | * License: GPL | ||
5 | * Copyright (c) 1999-2007 nagios-plugins team | ||
6 | * | ||
7 | * Last Modified: $Date$ | ||
8 | * | ||
9 | * Description: | ||
10 | * | ||
11 | * This file contains utilities for check_tcp. These are tested by libtap | ||
12 | * | ||
13 | * License Information: | ||
14 | * | ||
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 2 of the License, or | ||
18 | * (at your option) any later version. | ||
19 | * | ||
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. | ||
24 | * | ||
25 | * You should have received a copy of the GNU General Public License | ||
26 | * along with this program; if not, write to the Free Software | ||
27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 | * | ||
29 | * $Id$ | ||
30 | * | ||
31 | *****************************************************************************/ | ||
32 | |||
33 | #include "common.h" | ||
34 | #include "utils_tcp.h" | ||
35 | |||
36 | int | ||
37 | np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose) | ||
38 | { | ||
39 | int match = 0; | ||
40 | int i; | ||
41 | for (i = 0; i < expect_count; i++) { | ||
42 | if (verbose) | ||
43 | printf ("looking for [%s] %s [%s]\n", server_expect[i], | ||
44 | (exact_match) ? "in beginning of" : "anywhere in", | ||
45 | status); | ||
46 | |||
47 | if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) || | ||
48 | (! exact_match && strstr(status, server_expect[i]))) | ||
49 | { | ||
50 | if(verbose) puts("found it"); | ||
51 | match += 1; | ||
52 | } else | ||
53 | if(verbose) puts("couldn't find it"); | ||
54 | } | ||
55 | if ((all == true && match == expect_count) || | ||
56 | (! all && match >= 1)) { | ||
57 | return true; | ||
58 | } else | ||
59 | return false; | ||
60 | } | ||