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