common.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #include "config.h"
  35. #ifdef HAVE_FEATURES_H
  36. #include <features.h>
  37. #endif
  38. #include <stdio.h> /* obligatory includes */
  39. #include <stdlib.h>
  40. #include <errno.h>
  41. #ifdef HUGE_VAL_NEEDS_MATH_H
  42. #include <math.h>
  43. #endif
  44. #ifdef HAVE_STRINGS_H
  45. #include <strings.h>
  46. #endif
  47. #ifdef HAVE_STRING_H
  48. #include <string.h>
  49. #endif
  50. #ifdef HAVE_UNISTD_H
  51. #include <unistd.h>
  52. #endif
  53. #ifdef TIME_WITH_SYS_TIME
  54. # include <sys/time.h>
  55. # include <time.h>
  56. #else
  57. # ifdef HAVE_SYS_TIME_H
  58. # include <sys/time.h>
  59. # else
  60. # include <time.h>
  61. # endif
  62. #endif
  63. #ifdef HAVE_SYS_TYPES_H
  64. #include <sys/types.h>
  65. #endif
  66. #ifdef HAVE_SYS_SOCKET_H
  67. #include <sys/socket.h>
  68. #endif
  69. #ifdef HAVE_SIGNAL_H
  70. #include <signal.h>
  71. #endif
  72. /* TODO: define can be removed when all ifdef in each plugin has been removed */
  73. #define HAVE_GETOPT_H
  74. #include <getopt.h>
  75. #include <ctype.h>
  76. #ifdef HAVE_LWRES_NETDB_H
  77. #include <lwres/netdb.h>
  78. #else
  79. # if !HAVE_GETADDRINFO
  80. # include "getaddrinfo.h"
  81. # else
  82. # include <netdb.h>
  83. # endif
  84. #endif
  85. #ifdef HAVE_LOCALE_H
  86. #include <locale.h>
  87. #endif
  88. #ifdef HAVE_DECL_SWAPCTL
  89. # ifdef HAVE_SYS_SWAP_H
  90. # include <sys/swap.h>
  91. # endif
  92. # ifdef HAVE_SYS_STAT_H
  93. # include <sys/stat.h>
  94. # endif
  95. # ifdef HAVE_SYS_PARAM_H
  96. # include <sys/param.h>
  97. # endif
  98. #endif
  99. #ifndef SWAP_CONVERSION
  100. # define SWAP_CONVERSION 1
  101. #endif
  102. /*
  103. *
  104. * Missing Functions
  105. *
  106. */
  107. #ifndef HAVE_STRTOL
  108. # define strtol(a,b,c) atol((a))
  109. #endif
  110. #ifndef HAVE_STRTOUL
  111. # define strtoul(a,b,c) (unsigned long)atol((a))
  112. #endif
  113. #ifndef HAVE_ASPRINTF
  114. int asprintf(char **strp, const char *fmt, ...);
  115. #endif
  116. #ifndef HAVE_VASPRINTF
  117. /* int vasprintf(char **strp, const char *fmt, va_list ap); */
  118. #endif
  119. #ifndef HAVE_SNPRINTF
  120. int snprintf(char *str, size_t size, const char *format, ...);
  121. #endif
  122. #ifndef HAVE_VSNPRINTF
  123. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  124. #endif
  125. /*
  126. *
  127. * Standard Values
  128. *
  129. */
  130. enum {
  131. OK = 0,
  132. ERROR = -1
  133. };
  134. /* AIX seems to have this defined somewhere else */
  135. #ifndef FALSE
  136. enum {
  137. FALSE,
  138. TRUE
  139. };
  140. #endif
  141. enum {
  142. STATE_OK,
  143. STATE_WARNING,
  144. STATE_CRITICAL,
  145. STATE_UNKNOWN,
  146. STATE_DEPENDENT
  147. };
  148. enum {
  149. DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
  150. MAX_INPUT_BUFFER = 1024, /* max size of most buffers we use */
  151. MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
  152. };
  153. /*
  154. *
  155. * Internationalization
  156. *
  157. */
  158. #ifdef ENABLE_NLS
  159. # include "gettext.h"
  160. # define _(String) gettext (String)
  161. # define S_(String) gettext (String)
  162. # define gettext_noop(String) String
  163. # define N_(String) gettext_noop String
  164. #else
  165. # define _(String) (String)
  166. # define S_(String) (String)
  167. # define N_(String) String
  168. # define textdomain(Domain)
  169. # define bindtextdomain(Package, Directory)
  170. #endif
  171. /* For non-GNU compilers to ignore __attribute__ */
  172. #ifndef __GNUC__
  173. # define __attribute__(x) /* do nothing */
  174. #endif