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