common.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. #ifdef HAVE_SYSCONF__SC_NPROCESSORS_ONLN
  75. #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_ONLN)
  76. #else
  77. # ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF
  78. # define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
  79. # else
  80. # define GET_NUMBER_OF_CPUS() -1
  81. # endif
  82. #endif
  83. #ifdef TIME_WITH_SYS_TIME
  84. # include <sys/time.h>
  85. # include <time.h>
  86. #else
  87. # ifdef HAVE_SYS_TIME_H
  88. # include <sys/time.h>
  89. # else
  90. # include <time.h>
  91. # endif
  92. #endif
  93. #ifdef HAVE_SYS_TYPES_H
  94. #include <sys/types.h>
  95. #endif
  96. #ifdef HAVE_SYS_SOCKET_H
  97. #include <sys/socket.h>
  98. #endif
  99. #ifdef HAVE_SIGNAL_H
  100. #include <signal.h>
  101. #endif
  102. /* GNU Libraries */
  103. #include <getopt.h>
  104. #include "dirname.h"
  105. #ifdef HAVE_LOCALE_H
  106. #include <locale.h>
  107. #endif
  108. #ifdef HAVE_SYS_POLL_H
  109. # include "sys/poll.h"
  110. #endif
  111. /*
  112. *
  113. * Missing Functions
  114. *
  115. */
  116. #ifndef HAVE_STRTOL
  117. # define strtol(a,b,c) atol((a))
  118. #endif
  119. #ifndef HAVE_STRTOUL
  120. # define strtoul(a,b,c) (unsigned long)atol((a))
  121. #endif
  122. /* SSL implementations */
  123. #ifdef HAVE_GNUTLS_OPENSSL_H
  124. # include <gnutls/openssl.h>
  125. #else
  126. # define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */
  127. # ifdef HAVE_SSL_H
  128. # include <rsa.h>
  129. # include <crypto.h>
  130. # include <x509.h>
  131. # include <pem.h>
  132. # include <ssl.h>
  133. # include <err.h>
  134. # else
  135. # ifdef HAVE_OPENSSL_SSL_H
  136. # include <openssl/rsa.h>
  137. # include <openssl/crypto.h>
  138. # include <openssl/x509.h>
  139. # include <openssl/pem.h>
  140. # include <openssl/ssl.h>
  141. # include <openssl/err.h>
  142. # endif
  143. # endif
  144. #endif
  145. /*
  146. *
  147. * Standard Values
  148. *
  149. */
  150. enum {
  151. OK = 0,
  152. ERROR = -1
  153. };
  154. /* AIX seems to have this defined somewhere else */
  155. #ifndef FALSE
  156. enum {
  157. FALSE,
  158. TRUE
  159. };
  160. #endif
  161. enum {
  162. STATE_OK,
  163. STATE_WARNING,
  164. STATE_CRITICAL,
  165. STATE_UNKNOWN,
  166. STATE_DEPENDENT
  167. };
  168. enum {
  169. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  170. MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
  171. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  172. };
  173. /*
  174. *
  175. * Internationalization
  176. *
  177. */
  178. #include "gettext.h"
  179. #define _(String) gettext (String)
  180. #if ! ENABLE_NLS
  181. # undef textdomain
  182. # define textdomain(Domainname) /* empty */
  183. # undef bindtextdomain
  184. # define bindtextdomain(Domainname, Dirname) /* empty */
  185. #endif
  186. /* For non-GNU compilers to ignore __attribute__ */
  187. #ifndef __GNUC__
  188. # define __attribute__(x) /* do nothing */
  189. #endif
  190. #endif /* _COMMON_H_ */