4
0

common.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*****************************************************************************
  2. *
  3. * Nagios plugins common include file
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
  7. * Copyright (c) 2003-2007 Nagios Plugins Development Team
  8. *
  9. * Last Modified: $Date$
  10. *
  11. * Description:
  12. *
  13. * This file contains common include files and defines used in many of
  14. * the plugins.
  15. *
  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 3 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, see <http://www.gnu.org/licenses/>.
  29. *
  30. * $Id$
  31. *
  32. *****************************************************************************/
  33. #ifndef _COMMON_H_
  34. #define _COMMON_H_
  35. #include "config.h"
  36. #ifdef HAVE_FEATURES_H
  37. #include <features.h>
  38. #endif
  39. #include <stdio.h> /* obligatory includes */
  40. #include <stdlib.h>
  41. #include <errno.h>
  42. /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
  43. #if HAVE_INTTYPES_H
  44. # include <inttypes.h>
  45. #endif
  46. #if HAVE_STDINT_H
  47. # include <stdint.h>
  48. #endif
  49. #include <unistd.h>
  50. #ifndef UINTMAX_MAX
  51. # define UINTMAX_MAX ((uintmax_t) -1)
  52. #endif
  53. #include <limits.h> /* This is assumed true, because coreutils assume it too */
  54. #ifdef HAVE_MATH_H
  55. #include <math.h>
  56. #endif
  57. #ifdef HAVE_STRINGS_H
  58. #include <strings.h>
  59. #endif
  60. #ifdef HAVE_STRING_H
  61. #include <string.h>
  62. #endif
  63. #ifdef HAVE_UNISTD_H
  64. #include <unistd.h>
  65. #endif
  66. /* GET_NUMBER_OF_CPUS is a macro to return
  67. number of CPUs, if we can get that data.
  68. Use configure.in to test for various OS ways of
  69. getting that data
  70. Will return -1 if cannot get data
  71. */
  72. #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF
  73. #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
  74. #else
  75. #define GET_NUMBER_OF_CPUS() -1
  76. #endif
  77. #ifdef TIME_WITH_SYS_TIME
  78. # include <sys/time.h>
  79. # include <time.h>
  80. #else
  81. # ifdef HAVE_SYS_TIME_H
  82. # include <sys/time.h>
  83. # else
  84. # include <time.h>
  85. # endif
  86. #endif
  87. #ifdef HAVE_SYS_TYPES_H
  88. #include <sys/types.h>
  89. #endif
  90. #ifdef HAVE_SYS_SOCKET_H
  91. #include <sys/socket.h>
  92. #endif
  93. #ifdef HAVE_SIGNAL_H
  94. #include <signal.h>
  95. #endif
  96. /* GNU Libraries */
  97. #include <getopt.h>
  98. #include "dirname.h"
  99. #ifdef HAVE_LOCALE_H
  100. #include <locale.h>
  101. #endif
  102. #ifdef HAVE_SYS_POLL_H
  103. # include "sys/poll.h"
  104. #endif
  105. /*
  106. *
  107. * Missing Functions
  108. *
  109. */
  110. #ifndef HAVE_STRTOL
  111. # define strtol(a,b,c) atol((a))
  112. #endif
  113. #ifndef HAVE_STRTOUL
  114. # define strtoul(a,b,c) (unsigned long)atol((a))
  115. #endif
  116. /* SSL implementations */
  117. #ifdef HAVE_GNUTLS_OPENSSL_H
  118. # include <gnutls/openssl.h>
  119. #else
  120. # ifdef HAVE_SSL_H
  121. # include <rsa.h>
  122. # include <crypto.h>
  123. # include <x509.h>
  124. # include <pem.h>
  125. # include <ssl.h>
  126. # include <err.h>
  127. # else
  128. # ifdef HAVE_OPENSSL_SSL_H
  129. # include <openssl/rsa.h>
  130. # include <openssl/crypto.h>
  131. # include <openssl/x509.h>
  132. # include <openssl/pem.h>
  133. # include <openssl/ssl.h>
  134. # include <openssl/err.h>
  135. # endif
  136. # endif
  137. #endif
  138. /*
  139. *
  140. * Standard Values
  141. *
  142. */
  143. enum {
  144. OK = 0,
  145. ERROR = -1
  146. };
  147. /* AIX seems to have this defined somewhere else */
  148. #ifndef FALSE
  149. enum {
  150. FALSE,
  151. TRUE
  152. };
  153. #endif
  154. enum {
  155. STATE_OK,
  156. STATE_WARNING,
  157. STATE_CRITICAL,
  158. STATE_UNKNOWN,
  159. STATE_DEPENDENT
  160. };
  161. enum {
  162. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  163. MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
  164. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  165. };
  166. /*
  167. *
  168. * Internationalization
  169. *
  170. */
  171. #include "gettext.h"
  172. #define _(String) gettext (String)
  173. #if ! ENABLE_NLS
  174. # undef textdomain
  175. # define textdomain(Domainname) /* empty */
  176. # undef bindtextdomain
  177. # define bindtextdomain(Domainname, Dirname) /* empty */
  178. #endif
  179. /* For non-GNU compilers to ignore __attribute__ */
  180. #ifndef __GNUC__
  181. # define __attribute__(x) /* do nothing */
  182. #endif
  183. #endif /* _COMMON_H_ */