common.h 4.4 KB

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