common.h 4.4 KB

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