common.h 4.2 KB

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