Back to index

nagios-plugins  1.4.16
utils_tcp.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * 
00003 * Library for check_tcp
00004 * 
00005 * License: GPL
00006 * Copyright (c) 1999-2007 Nagios Plugins Development Team
00007 * 
00008 * Description:
00009 * 
00010 * This file contains utilities for check_tcp. These are tested by libtap
00011 * 
00012 * 
00013 * This program is free software: you can redistribute it and/or modify
00014 * it under the terms of the GNU General Public License as published by
00015 * the Free Software Foundation, either version 3 of the License, or
00016 * (at your option) any later version.
00017 * 
00018 * This program is distributed in the hope that it will be useful,
00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 * GNU General Public License for more details.
00022 * 
00023 * You should have received a copy of the GNU General Public License
00024 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025 * 
00026 * 
00027 *****************************************************************************/
00028 
00029 #include "common.h"
00030 #include "utils_tcp.h"
00031 
00032 int
00033 np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose)
00034 {
00035        int match = 0;
00036        int i;
00037        for (i = 0; i < expect_count; i++) {
00038               if (verbose)
00039                      printf ("looking for [%s] %s [%s]\n", server_expect[i],
00040                                    (exact_match) ? "in beginning of" : "anywhere in",
00041                                    status);
00042 
00043               if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
00044                      (! exact_match && strstr(status, server_expect[i])))
00045               {
00046                      if(verbose) puts("found it");
00047                      match += 1;
00048               } else
00049                      if(verbose) puts("couldn't find it");
00050        }
00051        if ((all == TRUE && match == expect_count) ||
00052               (! all && match >= 1)) {
00053               return TRUE;
00054        } else
00055               return FALSE;
00056 }