common.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /******************************************************************************
  2. *
  3. * Nagios plugins common include file
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
  7. *
  8. * Last Modified: 11-05-1999
  9. *
  10. * Description:
  11. *
  12. * This file contains common include files and defines used in many of
  13. * the plugins.
  14. *
  15. * License Information:
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. *
  31. *****************************************************************************/
  32. #include <stdio.h> /* obligatory includes */
  33. #include <stdlib.h>
  34. #include <errno.h>
  35. #include "config.h"
  36. #ifdef HAVE_STRINGS_H
  37. #include <strings.h>
  38. #endif
  39. #ifdef HAVE_STRING_H
  40. #include <string.h>
  41. #endif
  42. #ifdef HAVE_UNISTD_H
  43. #include <unistd.h>
  44. #endif
  45. #ifdef TIME_WITH_SYS_TIME
  46. # include <sys/time.h>
  47. # include <time.h>
  48. #else
  49. # ifdef HAVE_SYS_TIME_H
  50. # include <sys/time.h>
  51. # else
  52. # include <time.h>
  53. # endif
  54. #endif
  55. #ifdef HAVE_SYS_TYPES_H
  56. #include <sys/types.h>
  57. #endif
  58. #ifdef HAVE_SYS_SOCKET_H
  59. #include <sys/socket.h>
  60. #endif
  61. #ifdef HAVE_SIGNAL_H
  62. #include <signal.h>
  63. #endif
  64. /* TODO: define can be removed when all ifdef in each plugin has been removed */
  65. #define HAVE_GETOPT_H
  66. #include <getopt.h>
  67. #include <ctype.h>
  68. #if HAVE_LWRES_NETDB_H
  69. #include <lwres/netdb.h>
  70. #elif !HAVE_GETADDRINFO
  71. #include "getaddrinfo.h"
  72. #else
  73. #include <netdb.h>
  74. #endif
  75. /*
  76. *
  77. * Missing Functions
  78. *
  79. */
  80. #ifndef HAVE_STRTOL
  81. # define strtol(a,b,c) atol((a))
  82. #endif
  83. #ifndef HAVE_STRTOUL
  84. # define strtoul(a,b,c) (unsigned long)atol((a))
  85. #endif
  86. #ifndef HAVE_ASPRINTF
  87. int asprintf(char **strp, const char *fmt, ...);
  88. #endif
  89. #ifndef HAVE_VASPRINTF
  90. /* int vasprintf(char **strp, const char *fmt, va_list ap); */
  91. #endif
  92. #ifndef HAVE_SNPRINTF
  93. int snprintf(char *str, size_t size, const char *format, ...);
  94. #endif
  95. #ifndef HAVE_VSNPRINTF
  96. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  97. #endif
  98. /*
  99. *
  100. * Standard Values
  101. *
  102. */
  103. #define OK 0
  104. #define ERROR -1
  105. #define TRUE 1
  106. #define FALSE 0
  107. #define STATE_CRITICAL 2 /* service state return codes */
  108. #define STATE_WARNING 1
  109. #define STATE_OK 0
  110. #define STATE_UNKNOWN 3
  111. #define STATE_DEPENDENT 4
  112. #define DEFAULT_SOCKET_TIMEOUT 10 /* timeout after 10 seconds */
  113. #define MAX_INPUT_BUFFER 1024 /* max size of most buffers we use */
  114. #define MAX_HOST_ADDRESS_LENGTH 256 /* max size of a host address */
  115. #ifndef HAVE_SNPRINTF
  116. /*
  117. int snprintf (char *str, size_t n, const char *fmt, ...);
  118. int snprintf (char *str, size_t n, const char *fmt, ...)
  119. {
  120. char *buf;
  121. int i;
  122. int j=0;
  123. va_list ap;
  124. int d;
  125. char c, *p, *s;
  126. if((buf=malloc(n))==NULL){
  127. puts("could not malloc snprintf buffer\n");
  128. exit(-1);
  129. }
  130. va_start(ap,fmt);
  131. i=strlen(fmt);
  132. while((jj=index(&fmt[j],'%'))){
  133. j+=jj+1;
  134. switch fmt[j]
  135. {
  136. case 's':
  137. s = va_arg(ap, char *);
  138. i+=strlen(s);
  139. break;
  140. case 'd':
  141. d = va_arg(ap, int);
  142. i++;
  143. if (d<0) i++;
  144. while((d=d/10)>0) i++;
  145. break;
  146. case 'c':
  147. c = va_arg(ap, char);
  148. i++;
  149. break;
  150. }
  151. }
  152. va_end(ap);
  153. vsprintf(buf,fmt,ap);
  154. strcpy(str,buf[1:n-1]);
  155. exit(result);
  156. }
  157. */
  158. #endif