common.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #include <limits.h> /* This is assumed true, because coreutils assume it too */
  44. #ifdef HAVE_MATH_H
  45. #include <math.h>
  46. #endif
  47. #ifdef HAVE_STRINGS_H
  48. #include <strings.h>
  49. #endif
  50. #ifdef HAVE_STRING_H
  51. #include <string.h>
  52. #endif
  53. #ifdef HAVE_UNISTD_H
  54. #include <unistd.h>
  55. #endif
  56. #ifdef TIME_WITH_SYS_TIME
  57. # include <sys/time.h>
  58. # include <time.h>
  59. #else
  60. # ifdef HAVE_SYS_TIME_H
  61. # include <sys/time.h>
  62. # else
  63. # include <time.h>
  64. # endif
  65. #endif
  66. #ifdef HAVE_SYS_TYPES_H
  67. #include <sys/types.h>
  68. #endif
  69. #ifdef HAVE_SYS_SOCKET_H
  70. #include <sys/socket.h>
  71. #endif
  72. #ifdef HAVE_SIGNAL_H
  73. #include <signal.h>
  74. #endif
  75. #include <getopt.h>
  76. #include <ctype.h>
  77. #ifdef HAVE_LWRES_NETDB_H
  78. #include <lwres/netdb.h>
  79. #else
  80. # if !HAVE_GETADDRINFO
  81. # include "getaddrinfo.h"
  82. # else
  83. # include <netdb.h>
  84. # endif
  85. #endif
  86. #ifdef HAVE_LOCALE_H
  87. #include <locale.h>
  88. #endif
  89. #ifdef HAVE_DECL_SWAPCTL
  90. # ifdef HAVE_SYS_SWAP_H
  91. # include <sys/swap.h>
  92. # endif
  93. # ifdef HAVE_SYS_STAT_H
  94. # include <sys/stat.h>
  95. # endif
  96. # ifdef HAVE_SYS_PARAM_H
  97. # include <sys/param.h>
  98. # endif
  99. #endif
  100. #ifndef SWAP_CONVERSION
  101. # define SWAP_CONVERSION 1
  102. #endif
  103. #ifdef HAVE_SYS_POLL_H
  104. # include "sys/poll.h"
  105. #endif
  106. /*
  107. *
  108. * Missing Functions
  109. *
  110. */
  111. #ifndef HAVE_STRTOL
  112. # define strtol(a,b,c) atol((a))
  113. #endif
  114. #ifndef HAVE_STRTOUL
  115. # define strtoul(a,b,c) (unsigned long)atol((a))
  116. #endif
  117. #ifndef HAVE_ASPRINTF
  118. int asprintf(char **strp, const char *fmt, ...);
  119. #endif
  120. #ifndef HAVE_VASPRINTF
  121. /* int vasprintf(char **strp, const char *fmt, va_list ap); */
  122. #endif
  123. #ifndef HAVE_SNPRINTF
  124. int snprintf(char *str, size_t size, const char *format, ...);
  125. #endif
  126. #ifndef HAVE_VSNPRINTF
  127. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  128. #endif
  129. /* SSL implementations */
  130. #ifdef HAVE_GNUTLS_OPENSSL_H
  131. # include <gnutls/openssl.h>
  132. #else
  133. # ifdef HAVE_SSL_H
  134. # include <rsa.h>
  135. # include <crypto.h>
  136. # include <x509.h>
  137. # include <pem.h>
  138. # include <ssl.h>
  139. # include <err.h>
  140. # else
  141. # ifdef HAVE_OPENSSL_SSL_H
  142. # include <openssl/rsa.h>
  143. # include <openssl/crypto.h>
  144. # include <openssl/x509.h>
  145. # include <openssl/pem.h>
  146. # include <openssl/ssl.h>
  147. # include <openssl/err.h>
  148. # endif
  149. # endif
  150. #endif
  151. /*
  152. *
  153. * Standard Values
  154. *
  155. */
  156. enum {
  157. OK = 0,
  158. ERROR = -1
  159. };
  160. /* AIX seems to have this defined somewhere else */
  161. #ifndef FALSE
  162. enum {
  163. FALSE,
  164. TRUE
  165. };
  166. #endif
  167. /* Solaris does not have floorf, but floor works. Should probably be in configure */
  168. #if defined(__sun) || defined(__sun__)
  169. static inline float floorf (float x) { return floor(x); }
  170. #endif
  171. enum {
  172. STATE_OK,
  173. STATE_WARNING,
  174. STATE_CRITICAL,
  175. STATE_UNKNOWN,
  176. STATE_DEPENDENT
  177. };
  178. enum {
  179. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  180. MAX_INPUT_BUFFER = 1024, /* max size of most buffers we use */
  181. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  182. };
  183. /*
  184. *
  185. * Internationalization
  186. *
  187. */
  188. #include "gettext.h"
  189. #define _(String) gettext (String)
  190. #if ! ENABLE_NLS
  191. # undef textdomain
  192. # define textdomain(Domainname) /* empty */
  193. # undef bindtextdomain
  194. # define bindtextdomain(Domainname, Dirname) /* empty */
  195. #endif
  196. /* For non-GNU compilers to ignore __attribute__ */
  197. #ifndef __GNUC__
  198. # define __attribute__(x) /* do nothing */
  199. #endif
  200. #endif /* _COMMON_H_ */