common.h 4.9 KB

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