Code

- check_ntp:
[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>
48 #ifdef HAVE_MATH_H
49 #include <math.h>
50 #endif
52 #ifdef HAVE_STRINGS_H
53 #include <strings.h>
54 #endif
55 #ifdef HAVE_STRING_H
56 #include <string.h>
57 #endif
59 #ifdef HAVE_UNISTD_H
60 #include <unistd.h>
61 #endif
63 #ifdef TIME_WITH_SYS_TIME
64 # include <sys/time.h>
65 # include <time.h>
66 #else
67 # ifdef HAVE_SYS_TIME_H
68 #  include <sys/time.h>
69 # else
70 #  include <time.h>
71 # endif
72 #endif
74 #ifdef HAVE_SYS_TYPES_H
75 #include <sys/types.h>
76 #endif
78 #ifdef HAVE_SYS_SOCKET_H
79 #include <sys/socket.h>
80 #endif
82 #ifdef HAVE_SIGNAL_H
83 #include <signal.h>
84 #endif
86 /* TODO: define can be removed when all ifdef in each plugin has been removed */
87 #define HAVE_GETOPT_H
88 #include <getopt.h>
90 #include <ctype.h>
92 #ifdef HAVE_LWRES_NETDB_H
93 #include <lwres/netdb.h>
94 #else
95 # if !HAVE_GETADDRINFO
96 #  include "getaddrinfo.h"
97 # else
98 #  include <netdb.h>
99 # endif
100 #endif
102 #ifdef HAVE_LOCALE_H
103 #include <locale.h>
104 #endif
106 #ifdef HAVE_DECL_SWAPCTL
107 # ifdef HAVE_SYS_SWAP_H
108 #  include <sys/swap.h>
109 # endif
110 # ifdef HAVE_SYS_STAT_H
111 #  include <sys/stat.h>
112 # endif
113 # ifdef HAVE_SYS_PARAM_H
114 #  include <sys/param.h>
115 # endif
116 #endif
118 #ifndef SWAP_CONVERSION
119 # define SWAP_CONVERSION 1
120 #endif
122 #ifdef HAVE_SYS_POLL_H
123 # include "sys/poll.h"
124 #endif
126 /*
127  *
128  * Missing Functions
129  *
130  */
132 #ifndef HAVE_STRTOL
133 # define strtol(a,b,c) atol((a))
134 #endif
136 #ifndef HAVE_STRTOUL
137 # define strtoul(a,b,c) (unsigned long)atol((a))
138 #endif
140 #ifndef HAVE_ASPRINTF
141 int asprintf(char **strp, const char *fmt, ...);
142 #endif
144 #ifndef HAVE_VASPRINTF
145 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
146 #endif
148 #ifndef HAVE_SNPRINTF
149 int snprintf(char *str, size_t size, const  char  *format, ...);
150 #endif
152 #ifndef HAVE_VSNPRINTF
153 int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
154 #endif
156 /* SSL implementations */
157 #ifdef HAVE_GNUTLS_OPENSSL_H
158 #  include <gnutls/openssl.h>
159 #else
160 #  ifdef HAVE_SSL_H
161 #    include <rsa.h>
162 #    include <crypto.h>
163 #    include <x509.h>
164 #    include <pem.h>
165 #    include <ssl.h>
166 #    include <err.h>
167 #  else
168 #    ifdef HAVE_OPENSSL_SSL_H
169 #      include <openssl/rsa.h>
170 #      include <openssl/crypto.h>
171 #      include <openssl/x509.h>
172 #      include <openssl/pem.h>
173 #      include <openssl/ssl.h>
174 #      include <openssl/err.h>
175 #    endif
176 #  endif
177 #endif
179 /*
180  *
181  * Standard Values
182  *
183  */
185 enum {
186         OK = 0,
187         ERROR = -1
188 };
190 /* AIX seems to have this defined somewhere else */
191 #ifndef FALSE
192 enum {
193         FALSE,
194         TRUE
195 };
196 #endif
198 /* Solaris does not have floorf, but floor works. Should probably be in configure */
199 #if defined(__sun) || defined(__sun__)
200 static inline float floorf (float x) { return floor(x); }
201 #endif
203 enum {
204         STATE_OK,
205         STATE_WARNING,
206         STATE_CRITICAL,
207         STATE_UNKNOWN,
208         STATE_DEPENDENT
209 };
211 enum {
212         DEFAULT_SOCKET_TIMEOUT = 10,     /* timeout after 10 seconds */
213         MAX_INPUT_BUFFER = 1024,             /* max size of most buffers we use */
214         MAX_HOST_ADDRESS_LENGTH = 256    /* max size of a host address */
215 };
217 /*
218  *
219  * Internationalization
220  *
221  */
222 #include "gettext.h"
223 #define _(String) gettext (String)
225 /* For non-GNU compilers to ignore __attribute__ */
226 #ifndef __GNUC__
227 # define __attribute__(x) /* do nothing */
228 #endif
230 #endif /* _COMMON_H_ */