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 HAVE_STRINGS_H
44 #include <strings.h>
45 #endif
46 #ifdef HAVE_STRING_H
47 #include <string.h>
48 #endif
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
54 #ifdef TIME_WITH_SYS_TIME
55 # include <sys/time.h>
56 # include <time.h>
57 #else
58 # ifdef HAVE_SYS_TIME_H
59 # include <sys/time.h>
60 # else
61 # include <time.h>
62 # endif
63 #endif
65 #ifdef HAVE_SYS_TYPES_H
66 #include <sys/types.h>
67 #endif
69 #ifdef HAVE_SYS_SOCKET_H
70 #include <sys/socket.h>
71 #endif
73 #ifdef HAVE_SIGNAL_H
74 #include <signal.h>
75 #endif
77 /* TODO: define can be removed when all ifdef in each plugin has been removed */
78 #define HAVE_GETOPT_H
79 #include <getopt.h>
81 #include <ctype.h>
83 #ifdef HAVE_LWRES_NETDB_H
84 #include <lwres/netdb.h>
85 #else
86 # if !HAVE_GETADDRINFO
87 # include "getaddrinfo.h"
88 # else
89 # include <netdb.h>
90 # endif
91 #endif
93 #ifdef HAVE_LOCALE_H
94 #include <locale.h>
95 #endif
97 /*
98 *
99 * Missing Functions
100 *
101 */
103 #ifndef HAVE_STRTOL
104 # define strtol(a,b,c) atol((a))
105 #endif
107 #ifndef HAVE_STRTOUL
108 # define strtoul(a,b,c) (unsigned long)atol((a))
109 #endif
111 #ifndef HAVE_ASPRINTF
112 int asprintf(char **strp, const char *fmt, ...);
113 #endif
115 #ifndef HAVE_VASPRINTF
116 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
117 #endif
119 #ifndef HAVE_SNPRINTF
120 int snprintf(char *str, size_t size, const char *format, ...);
121 #endif
123 #ifndef HAVE_VSNPRINTF
124 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
125 #endif
127 /*
128 *
129 * Standard Values
130 *
131 */
133 enum {
134 OK = 0,
135 ERROR = -1
136 };
138 enum {
139 FALSE,
140 TRUE
141 };
143 enum {
144 STATE_OK,
145 STATE_WARNING,
146 STATE_CRITICAL,
147 STATE_UNKNOWN,
148 STATE_DEPENDENT
149 };
151 enum {
152 DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
153 MAX_INPUT_BUFFER = 1024, /* max size of most buffers we use */
154 MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
155 };
157 /*
158 *
159 * Internationalization
160 *
161 */
163 #ifdef ENABLE_NLS
164 # include "gettext.h"
165 # define _(String) gettext (String)
166 # define S_(String) gettext (String)
167 # define gettext_noop(String) String
168 # define N_(String) gettext_noop String
169 #else
170 # define _(String) (String)
171 # define S_(String) (String)
172 # define N_(String) String
173 # define textdomain(Domain)
174 # define bindtextdomain(Package, Directory)
175 #endif