Code

Fix for CHAR_MAX on Solaris 9
[nagiosplug.git] / plugins / common.h
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"
40 #ifdef HAVE_FEATURES_H
41 #include <features.h>
42 #endif
44 #include <stdio.h>                                                      /* obligatory includes */
45 #include <stdlib.h>
46 #include <errno.h>
47 #include <limits.h>     /* This is assumed true, because coreutils assume it too */
49 #ifdef HAVE_MATH_H
50 #include <math.h>
51 #endif
53 #ifdef HAVE_STRINGS_H
54 #include <strings.h>
55 #endif
56 #ifdef HAVE_STRING_H
57 #include <string.h>
58 #endif
60 #ifdef HAVE_UNISTD_H
61 #include <unistd.h>
62 #endif
64 #ifdef TIME_WITH_SYS_TIME
65 # include <sys/time.h>
66 # include <time.h>
67 #else
68 # ifdef HAVE_SYS_TIME_H
69 #  include <sys/time.h>
70 # else
71 #  include <time.h>
72 # endif
73 #endif
75 #ifdef HAVE_SYS_TYPES_H
76 #include <sys/types.h>
77 #endif
79 #ifdef HAVE_SYS_SOCKET_H
80 #include <sys/socket.h>
81 #endif
83 #ifdef HAVE_SIGNAL_H
84 #include <signal.h>
85 #endif
87 #include <getopt.h>
88 #include <ctype.h>
90 #ifdef HAVE_LWRES_NETDB_H
91 #include <lwres/netdb.h>
92 #else
93 # if !HAVE_GETADDRINFO
94 #  include "getaddrinfo.h"
95 # else
96 #  include <netdb.h>
97 # endif
98 #endif
100 #ifdef HAVE_LOCALE_H
101 #include <locale.h>
102 #endif
104 #ifdef HAVE_DECL_SWAPCTL
105 # ifdef HAVE_SYS_SWAP_H
106 #  include <sys/swap.h>
107 # endif
108 # ifdef HAVE_SYS_STAT_H
109 #  include <sys/stat.h>
110 # endif
111 # ifdef HAVE_SYS_PARAM_H
112 #  include <sys/param.h>
113 # endif
114 #endif
116 #ifndef SWAP_CONVERSION
117 # define SWAP_CONVERSION 1
118 #endif
120 #ifdef HAVE_SYS_POLL_H
121 # include "sys/poll.h"
122 #endif
124 /*
125  *
126  * Missing Functions
127  *
128  */
130 #ifndef HAVE_STRTOL
131 # define strtol(a,b,c) atol((a))
132 #endif
134 #ifndef HAVE_STRTOUL
135 # define strtoul(a,b,c) (unsigned long)atol((a))
136 #endif
138 #ifndef HAVE_ASPRINTF
139 int asprintf(char **strp, const char *fmt, ...);
140 #endif
142 #ifndef HAVE_VASPRINTF
143 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
144 #endif
146 #ifndef HAVE_SNPRINTF
147 int snprintf(char *str, size_t size, const  char  *format, ...);
148 #endif
150 #ifndef HAVE_VSNPRINTF
151 int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
152 #endif
154 /* SSL implementations */
155 #ifdef HAVE_GNUTLS_OPENSSL_H
156 #  include <gnutls/openssl.h>
157 #else
158 #  ifdef HAVE_SSL_H
159 #    include <rsa.h>
160 #    include <crypto.h>
161 #    include <x509.h>
162 #    include <pem.h>
163 #    include <ssl.h>
164 #    include <err.h>
165 #  else
166 #    ifdef HAVE_OPENSSL_SSL_H
167 #      include <openssl/rsa.h>
168 #      include <openssl/crypto.h>
169 #      include <openssl/x509.h>
170 #      include <openssl/pem.h>
171 #      include <openssl/ssl.h>
172 #      include <openssl/err.h>
173 #    endif
174 #  endif
175 #endif
177 /*
178  *
179  * Standard Values
180  *
181  */
183 enum {
184         OK = 0,
185         ERROR = -1
186 };
188 /* AIX seems to have this defined somewhere else */
189 #ifndef FALSE
190 enum {
191         FALSE,
192         TRUE
193 };
194 #endif
196 /* Solaris does not have floorf, but floor works. Should probably be in configure */
197 #if defined(__sun) || defined(__sun__)
198 static inline float floorf (float x) { return floor(x); }
199 #endif
201 enum {
202         STATE_OK,
203         STATE_WARNING,
204         STATE_CRITICAL,
205         STATE_UNKNOWN,
206         STATE_DEPENDENT
207 };
209 enum {
210         DEFAULT_SOCKET_TIMEOUT = 10,     /* timeout after 10 seconds */
211         MAX_INPUT_BUFFER = 1024,             /* max size of most buffers we use */
212         MAX_HOST_ADDRESS_LENGTH = 256    /* max size of a host address */
213 };
215 /*
216  *
217  * Internationalization
218  *
219  */
220 #include "gettext.h"
221 #define _(String) gettext (String)
222 #if ! ENABLE_NLS
223 # undef textdomain
224 # define textdomain(Domainname) /* empty */
225 # undef bindtextdomain
226 # define bindtextdomain(Domainname, Dirname) /* empty */
227 #endif
229 /* For non-GNU compilers to ignore __attribute__ */
230 #ifndef __GNUC__
231 # define __attribute__(x) /* do nothing */
232 #endif
234 #endif /* _COMMON_H_ */