common.h 3.4 KB

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