common.h 4.5 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. * Last Modified: $Date$
  10. *
  11. * Description:
  12. *
  13. * This file contains common include files and defines used in many of
  14. * the plugins.
  15. *
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. *
  30. * $Id$
  31. *
  32. *****************************************************************************/
  33. #ifndef _COMMON_H_
  34. #define _COMMON_H_
  35. #include "config.h"
  36. /* This needs to be removed for Solaris servers, where 64 bit files, but 32 bit architecture
  37. This needs to be done early on because subsequent system includes use _FILE_OFFSET_BITS
  38. Cannot remove from config.h because is included by regex.c from lib/ */
  39. #if __sun__ && !defined(_LP64) && _FILE_OFFSET_BITS == 64
  40. #undef _FILE_OFFSET_BITS
  41. #endif
  42. #ifdef HAVE_FEATURES_H
  43. #include <features.h>
  44. #endif
  45. #include <stdio.h> /* obligatory includes */
  46. #include <stdlib.h>
  47. #include <errno.h>
  48. /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
  49. #if HAVE_INTTYPES_H
  50. # include <inttypes.h>
  51. #endif
  52. #if HAVE_STDINT_H
  53. # include <stdint.h>
  54. #endif
  55. #include <unistd.h>
  56. #ifndef UINTMAX_MAX
  57. # define UINTMAX_MAX ((uintmax_t) -1)
  58. #endif
  59. #include <limits.h> /* This is assumed true, because coreutils assume it too */
  60. #ifdef HAVE_MATH_H
  61. #include <math.h>
  62. #endif
  63. #ifdef HAVE_STRINGS_H
  64. #include <strings.h>
  65. #endif
  66. #ifdef HAVE_STRING_H
  67. #include <string.h>
  68. #endif
  69. #ifdef HAVE_UNISTD_H
  70. #include <unistd.h>
  71. #endif
  72. /* GET_NUMBER_OF_CPUS is a macro to return
  73. number of CPUs, if we can get that data.
  74. Use configure.in to test for various OS ways of
  75. getting that data
  76. Will return -1 if cannot get data
  77. */
  78. #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF
  79. #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
  80. #else
  81. #define GET_NUMBER_OF_CPUS() -1
  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. # ifdef HAVE_SSL_H
  127. # include <rsa.h>
  128. # include <crypto.h>
  129. # include <x509.h>
  130. # include <pem.h>
  131. # include <ssl.h>
  132. # include <err.h>
  133. # else
  134. # ifdef HAVE_OPENSSL_SSL_H
  135. # include <openssl/rsa.h>
  136. # include <openssl/crypto.h>
  137. # include <openssl/x509.h>
  138. # include <openssl/pem.h>
  139. # include <openssl/ssl.h>
  140. # include <openssl/err.h>
  141. # endif
  142. # endif
  143. #endif
  144. /*
  145. *
  146. * Standard Values
  147. *
  148. */
  149. enum {
  150. OK = 0,
  151. ERROR = -1
  152. };
  153. /* AIX seems to have this defined somewhere else */
  154. #ifndef FALSE
  155. enum {
  156. FALSE,
  157. TRUE
  158. };
  159. #endif
  160. enum {
  161. STATE_OK,
  162. STATE_WARNING,
  163. STATE_CRITICAL,
  164. STATE_UNKNOWN,
  165. STATE_DEPENDENT
  166. };
  167. enum {
  168. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  169. MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
  170. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  171. };
  172. /*
  173. *
  174. * Internationalization
  175. *
  176. */
  177. #include "gettext.h"
  178. #define _(String) gettext (String)
  179. #if ! ENABLE_NLS
  180. # undef textdomain
  181. # define textdomain(Domainname) /* empty */
  182. # undef bindtextdomain
  183. # define bindtextdomain(Domainname, Dirname) /* empty */
  184. #endif
  185. /* For non-GNU compilers to ignore __attribute__ */
  186. #ifndef __GNUC__
  187. # define __attribute__(x) /* do nothing */
  188. #endif
  189. #endif /* _COMMON_H_ */