summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/utils_tcp.c60
-rw-r--r--lib/utils_tcp.h4
3 files changed, 66 insertions, 2 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 3909bb9b..5d0f6352 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,8 +5,8 @@ SUBDIRS = tests
5noinst_LIBRARIES = libnagiosplug.a 5noinst_LIBRARIES = libnagiosplug.a
6 6
7 7
8libnagiosplug_a_SOURCES = utils_base.c utils_disk.c 8libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c
9EXTRA_DIST = utils_base.h utils_disk.h 9EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h
10 10
11INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins 11INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
12 12
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
36int
37np_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}
diff --git a/lib/utils_tcp.h b/lib/utils_tcp.h
new file mode 100644
index 00000000..06506f32
--- /dev/null
+++ b/lib/utils_tcp.h
@@ -0,0 +1,4 @@
1/* Header file for utils_disk */
2
3int np_expect_match(char* status, char** server_expect, int server_expect_count,
4 int all, int exact_match, int verbose);