common.h 4.1 KB

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