Code

Using swapctl for Solaris, Tru64 and *BSD (Sean Finney)
[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  *****************************************************************************/
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 #ifdef HAVE_DECL_SWAPCTL
102 # ifdef HAVE_SYS_SWAP_H
103 #  include <sys/swap.h>
104 # endif
105 # ifdef HAVE_SYS_STAT_H
106 #  include <sys/stat.h>
107 # endif
108 # ifdef HAVE_SYS_PARAM_H
109 #  include <sys/param.h>
110 # endif
111 #endif
113 #ifndef SWAP_CONVERSION
114 # define SWAP_CONVERSION 1
115 #endif
117 /*
118  *
119  * Missing Functions
120  *
121  */
123 #ifndef HAVE_STRTOL
124 # define strtol(a,b,c) atol((a))
125 #endif
127 #ifndef HAVE_STRTOUL
128 # define strtoul(a,b,c) (unsigned long)atol((a))
129 #endif
131 #ifndef HAVE_ASPRINTF
132 int asprintf(char **strp, const char *fmt, ...);
133 #endif
135 #ifndef HAVE_VASPRINTF
136 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
137 #endif
139 #ifndef HAVE_SNPRINTF
140 int snprintf(char *str, size_t size, const  char  *format, ...);
141 #endif
143 #ifndef HAVE_VSNPRINTF
144 int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
145 #endif
147 /*
148  *
149  * Standard Values
150  *
151  */
153 enum {
154         OK = 0,
155         ERROR = -1
156 };
158 /* AIX seems to have this defined somewhere else */
159 #ifndef FALSE
160 enum {
161         FALSE,
162         TRUE
163 };
164 #endif
166 enum {
167         STATE_OK,
168         STATE_WARNING,
169         STATE_CRITICAL,
170         STATE_UNKNOWN,
171         STATE_DEPENDENT
172 };
174 enum {
175         DEFAULT_SOCKET_TIMEOUT = 10,     /* timeout after 10 seconds */
176         MAX_INPUT_BUFFER = 1024,             /* max size of most buffers we use */
177         MAX_HOST_ADDRESS_LENGTH = 256    /* max size of a host address */
178 };
180 /*
181  *
182  * Internationalization
183  *
184  */
186 #ifdef ENABLE_NLS
187 #  include "gettext.h"
188 #  define _(String) gettext (String)
189 #  define S_(String) gettext (String)
190 #  define gettext_noop(String) String
191 #  define N_(String) gettext_noop String
192 #else
193 #  define _(String) (String)
194 #  define S_(String) (String)
195 #  define N_(String) String
196 #  define textdomain(Domain)
197 #  define bindtextdomain(Package, Directory)
198 #endif
200 /* For non-GNU compilers to ignore __attribute__ */
201 #ifndef __GNUC__
202 # define __attribute__(x) /* do nothing */
203 #endif