utils_tcp.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "common.h"
  33. #include "utils_tcp.h"
  34. int
  35. np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose)
  36. {
  37. int match = 0;
  38. int i;
  39. for (i = 0; i < expect_count; i++) {
  40. if (verbose)
  41. printf ("looking for [%s] %s [%s]\n", server_expect[i],
  42. (exact_match) ? "in beginning of" : "anywhere in",
  43. status);
  44. if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
  45. (! exact_match && strstr(status, server_expect[i])))
  46. {
  47. if(verbose) puts("found it");
  48. match += 1;
  49. } else
  50. if(verbose) puts("couldn't find it");
  51. }
  52. if ((all == TRUE && match == expect_count) ||
  53. (! all && match >= 1)) {
  54. return TRUE;
  55. } else
  56. return FALSE;
  57. }