common.h 4.8 KB

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