common.h 3.3 KB

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