common.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /******************************************************************************
  2. *
  3. * Nagios plugins common include file
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
  7. *
  8. * Last Modified: 11-05-1999
  9. *
  10. * Description:
  11. *
  12. * This file contains common include files and defines used in many of
  13. * the plugins.
  14. *
  15. * License Information:
  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 2 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, write to the Free Software
  29. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. *
  31. * $Id$
  32. *
  33. *****************************************************************************/
  34. #ifndef _COMMON_H_
  35. #define _COMMON_H_
  36. #include "config.h"
  37. #ifdef HAVE_FEATURES_H
  38. #include <features.h>
  39. #endif
  40. #include <stdio.h> /* obligatory includes */
  41. #include <stdlib.h>
  42. #include <errno.h>
  43. /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
  44. #if HAVE_INTTYPES_H
  45. # include <inttypes.h>
  46. #endif
  47. #if HAVE_STDINT_H
  48. # include <stdint.h>
  49. #endif
  50. #include <unistd.h>
  51. #ifndef UINTMAX_MAX
  52. # define UINTMAX_MAX ((uintmax_t) -1)
  53. #endif
  54. #include <limits.h> /* This is assumed true, because coreutils assume it too */
  55. #ifdef HAVE_MATH_H
  56. #include <math.h>
  57. #endif
  58. #ifdef HAVE_STRINGS_H
  59. #include <strings.h>
  60. #endif
  61. #ifdef HAVE_STRING_H
  62. #include <string.h>
  63. #endif
  64. #ifdef HAVE_UNISTD_H
  65. #include <unistd.h>
  66. #endif
  67. #ifdef TIME_WITH_SYS_TIME
  68. # include <sys/time.h>
  69. # include <time.h>
  70. #else
  71. # ifdef HAVE_SYS_TIME_H
  72. # include <sys/time.h>
  73. # else
  74. # include <time.h>
  75. # endif
  76. #endif
  77. #ifdef HAVE_SYS_TYPES_H
  78. #include <sys/types.h>
  79. #endif
  80. #ifdef HAVE_SYS_SOCKET_H
  81. #include <sys/socket.h>
  82. #endif
  83. #ifdef HAVE_SIGNAL_H
  84. #include <signal.h>
  85. #endif
  86. #include <getopt.h>
  87. #include <ctype.h>
  88. #ifdef HAVE_LWRES_NETDB_H
  89. #include <lwres/netdb.h>
  90. #else
  91. # if !HAVE_GETADDRINFO
  92. # include "getaddrinfo.h"
  93. # else
  94. # include <netdb.h>
  95. # endif
  96. #endif
  97. #ifdef HAVE_LOCALE_H
  98. #include <locale.h>
  99. #endif
  100. /* Fixes "Cannot use swapctl in the large files compilation environment" error on Solaris */
  101. #ifdef _FILE_OFFSET_BITS
  102. #undef _FILE_OFFSET_BITS
  103. #endif
  104. #ifdef HAVE_DECL_SWAPCTL
  105. # ifdef HAVE_SYS_SWAP_H
  106. # include <sys/swap.h>
  107. # endif
  108. # ifdef HAVE_SYS_STAT_H
  109. # include <sys/stat.h>
  110. # endif
  111. # ifdef HAVE_SYS_PARAM_H
  112. # include <sys/param.h>
  113. # endif
  114. #endif
  115. #ifndef SWAP_CONVERSION
  116. # define SWAP_CONVERSION 1
  117. #endif
  118. #ifdef HAVE_SYS_POLL_H
  119. # include "sys/poll.h"
  120. #endif
  121. /*
  122. *
  123. * Missing Functions
  124. *
  125. */
  126. #ifndef HAVE_STRTOL
  127. # define strtol(a,b,c) atol((a))
  128. #endif
  129. #ifndef HAVE_STRTOUL
  130. # define strtoul(a,b,c) (unsigned long)atol((a))
  131. #endif
  132. #ifndef HAVE_ASPRINTF
  133. int asprintf(char **strp, const char *fmt, ...);
  134. #endif
  135. #ifndef HAVE_VASPRINTF
  136. /* int vasprintf(char **strp, const char *fmt, va_list ap); */
  137. #endif
  138. #ifndef HAVE_SNPRINTF
  139. int snprintf(char *str, size_t size, const char *format, ...);
  140. #endif
  141. #ifndef HAVE_VSNPRINTF
  142. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  143. #endif
  144. /* SSL implementations */
  145. #ifdef HAVE_GNUTLS_OPENSSL_H
  146. # include <gnutls/openssl.h>
  147. #else
  148. # ifdef HAVE_SSL_H
  149. # include <rsa.h>
  150. # include <crypto.h>
  151. # include <x509.h>
  152. # include <pem.h>
  153. # include <ssl.h>
  154. # include <err.h>
  155. # else
  156. # ifdef HAVE_OPENSSL_SSL_H
  157. # include <openssl/rsa.h>
  158. # include <openssl/crypto.h>
  159. # include <openssl/x509.h>
  160. # include <openssl/pem.h>
  161. # include <openssl/ssl.h>
  162. # include <openssl/err.h>
  163. # endif
  164. # endif
  165. #endif
  166. /*
  167. *
  168. * Standard Values
  169. *
  170. */
  171. enum {
  172. OK = 0,
  173. ERROR = -1
  174. };
  175. /* AIX seems to have this defined somewhere else */
  176. #ifndef FALSE
  177. enum {
  178. FALSE,
  179. TRUE
  180. };
  181. #endif
  182. /* Solaris does not have floorf, but floor works. Should probably be in configure */
  183. #if defined(__sun) || defined(__sun__)
  184. static inline float floorf (float x) { return floor(x); }
  185. #endif
  186. enum {
  187. STATE_OK,
  188. STATE_WARNING,
  189. STATE_CRITICAL,
  190. STATE_UNKNOWN,
  191. STATE_DEPENDENT
  192. };
  193. enum {
  194. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  195. MAX_INPUT_BUFFER = 1024, /* max size of most buffers we use */
  196. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  197. };
  198. /*
  199. *
  200. * Internationalization
  201. *
  202. */
  203. #include "gettext.h"
  204. #define _(String) gettext (String)
  205. #if ! ENABLE_NLS
  206. # undef textdomain
  207. # define textdomain(Domainname) /* empty */
  208. # undef bindtextdomain
  209. # define bindtextdomain(Domainname, Dirname) /* empty */
  210. #endif
  211. /* For non-GNU compilers to ignore __attribute__ */
  212. #ifndef __GNUC__
  213. # define __attribute__(x) /* do nothing */
  214. #endif
  215. #endif /* _COMMON_H_ */