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 #if 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 /*
94 *
95 * Missing Functions
96 *
97 */
99 #ifndef HAVE_STRTOL
100 # define strtol(a,b,c) atol((a))
101 #endif
103 #ifndef HAVE_STRTOUL
104 # define strtoul(a,b,c) (unsigned long)atol((a))
105 #endif
107 #ifndef HAVE_ASPRINTF
108 int asprintf(char **strp, const char *fmt, ...);
109 #endif
111 #ifndef HAVE_VASPRINTF
112 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
113 #endif
115 #ifndef HAVE_SNPRINTF
116 int snprintf(char *str, size_t size, const char *format, ...);
117 #endif
119 #ifndef HAVE_VSNPRINTF
120 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
121 #endif
123 /*
124 *
125 * Standard Values
126 *
127 */
129 enum {
130 OK = 0,
131 ERROR = -1
132 };
134 enum {
135 FALSE,
136 TRUE
137 };
139 enum {
140 STATE_OK,
141 STATE_WARNING,
142 STATE_CRITICAL,
143 STATE_UNKNOWN,
144 STATE_DEPENDENT
145 };
147 enum {
148 DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
149 MAX_INPUT_BUFFER = 1024, /* max size of most buffers we use */
150 MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
151 };
153 /*
154 *
155 * Internationalization
156 *
157 */
159 #if ENABLE_NLS
160 # include "gettext.h"
161 # define _(String) gettext (String)
162 # define S_(String) gettext (String)
163 # define gettext_noop(String) String
164 # define N_(String) gettext_noop String
165 #else
166 # define _(String) (String)
167 # define S_(String) (String)
168 # define N_(String) String
169 # define textdomain(Domain)
170 # define bindtextdomain(Package, Directory)
171 #endif