4
0

common.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #include <locale.h>
  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. # define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */
  123. # ifdef HAVE_SSL_H
  124. # include <rsa.h>
  125. # include <crypto.h>
  126. # include <x509.h>
  127. # include <pem.h>
  128. # include <ssl.h>
  129. # include <err.h>
  130. # else
  131. # ifdef HAVE_OPENSSL_SSL_H
  132. # include <openssl/rsa.h>
  133. # include <openssl/crypto.h>
  134. # include <openssl/x509.h>
  135. # include <openssl/pem.h>
  136. # include <openssl/ssl.h>
  137. # include <openssl/err.h>
  138. # endif
  139. # endif
  140. #endif
  141. /*
  142. *
  143. * Standard Values
  144. *
  145. */
  146. enum {
  147. OK = 0,
  148. ERROR = -1
  149. };
  150. /* AIX seems to have this defined somewhere else */
  151. #ifndef FALSE
  152. enum {
  153. FALSE,
  154. TRUE
  155. };
  156. #endif
  157. enum {
  158. STATE_OK,
  159. STATE_WARNING,
  160. STATE_CRITICAL,
  161. STATE_UNKNOWN,
  162. STATE_DEPENDENT
  163. };
  164. enum {
  165. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  166. MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
  167. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  168. };
  169. /*
  170. *
  171. * Internationalization
  172. *
  173. */
  174. #include "gettext.h"
  175. #define _(String) gettext (String)
  176. #if ! ENABLE_NLS
  177. # undef textdomain
  178. # define textdomain(Domainname) /* empty */
  179. # undef bindtextdomain
  180. # define bindtextdomain(Domainname, Dirname) /* empty */
  181. #endif
  182. /* For non-GNU compilers to ignore __attribute__ */
  183. #ifndef __GNUC__
  184. # define __attribute__(x) /* do nothing */
  185. #endif
  186. #endif /* _COMMON_H_ */