common.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. #include "vasprintf.h"
  106. #include "snprintf.h"
  107. #include "vsnprintf.h"
  108. #ifdef HAVE_LOCALE_H
  109. #include <locale.h>
  110. #endif
  111. #ifdef HAVE_SYS_POLL_H
  112. # include "sys/poll.h"
  113. #endif
  114. /*
  115. *
  116. * Missing Functions
  117. *
  118. */
  119. #ifndef HAVE_STRTOL
  120. # define strtol(a,b,c) atol((a))
  121. #endif
  122. #ifndef HAVE_STRTOUL
  123. # define strtoul(a,b,c) (unsigned long)atol((a))
  124. #endif
  125. /* SSL implementations */
  126. #ifdef HAVE_GNUTLS_OPENSSL_H
  127. # include <gnutls/openssl.h>
  128. #else
  129. # ifdef HAVE_SSL_H
  130. # include <rsa.h>
  131. # include <crypto.h>
  132. # include <x509.h>
  133. # include <pem.h>
  134. # include <ssl.h>
  135. # include <err.h>
  136. # else
  137. # ifdef HAVE_OPENSSL_SSL_H
  138. # include <openssl/rsa.h>
  139. # include <openssl/crypto.h>
  140. # include <openssl/x509.h>
  141. # include <openssl/pem.h>
  142. # include <openssl/ssl.h>
  143. # include <openssl/err.h>
  144. # endif
  145. # endif
  146. #endif
  147. /*
  148. *
  149. * Standard Values
  150. *
  151. */
  152. enum {
  153. OK = 0,
  154. ERROR = -1
  155. };
  156. /* AIX seems to have this defined somewhere else */
  157. #ifndef FALSE
  158. enum {
  159. FALSE,
  160. TRUE
  161. };
  162. #endif
  163. /* Solaris does not have floorf, but floor works. Should probably be in configure */
  164. #if defined(__sun) || defined(__sun__)
  165. static inline float floorf (float x) { return floor(x); }
  166. #endif
  167. enum {
  168. STATE_OK,
  169. STATE_WARNING,
  170. STATE_CRITICAL,
  171. STATE_UNKNOWN,
  172. STATE_DEPENDENT
  173. };
  174. enum {
  175. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  176. MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
  177. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  178. };
  179. /*
  180. *
  181. * Internationalization
  182. *
  183. */
  184. #include "gettext.h"
  185. #define _(String) gettext (String)
  186. #if ! ENABLE_NLS
  187. # undef textdomain
  188. # define textdomain(Domainname) /* empty */
  189. # undef bindtextdomain
  190. # define bindtextdomain(Domainname, Dirname) /* empty */
  191. #endif
  192. /* For non-GNU compilers to ignore __attribute__ */
  193. #ifndef __GNUC__
  194. # define __attribute__(x) /* do nothing */
  195. #endif
  196. #endif /* _COMMON_H_ */