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 <stdio.h> /* obligatory includes */
34 #include <stdlib.h>
35 #include <errno.h>
37 #include "config.h"
39 #ifdef HAVE_STRINGS_H
40 #include <strings.h>
41 #endif
42 #ifdef HAVE_STRING_H
43 #include <string.h>
44 #endif
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
50 #ifdef TIME_WITH_SYS_TIME
51 # include <sys/time.h>
52 # include <time.h>
53 #else
54 # ifdef HAVE_SYS_TIME_H
55 # include <sys/time.h>
56 # else
57 # include <time.h>
58 # endif
59 #endif
61 #ifdef HAVE_SYS_TYPES_H
62 #include <sys/types.h>
63 #endif
65 #ifdef HAVE_SIGNAL_H
66 #include <signal.h>
67 #endif
69 /* TODO: define can be removed when all ifdef in each plugin has been removed */
70 #define HAVE_GETOPT_H
71 #include <getopt.h>
73 #include <ctype.h>
75 #if HAVE_LWRES_NETDB_H
76 #include <lwres/netdb.h>
77 #elif !HAVE_GETADDRINFO
78 #include "getaddrinfo.h"
79 #else
80 #include <netdb.h>
81 #endif
83 /*
84 *
85 * Missing Functions
86 *
87 */
89 #ifndef HAVE_STRTOL
90 # define strtol(a,b,c) atol((a))
91 #endif
93 #ifndef HAVE_STRTOUL
94 # define strtoul(a,b,c) (unsigned long)atol((a))
95 #endif
97 #ifndef HAVE_ASPRINTF
98 int asprintf(char **strp, const char *fmt, ...);
99 #endif
101 #ifndef HAVE_VASPRINTF
102 /* int vasprintf(char **strp, const char *fmt, va_list ap); */
103 #endif
105 #ifndef HAVE_SNPRINTF
106 int snprintf(char *str, size_t size, const char *format, ...);
107 #endif
109 #ifndef HAVE_VSNPRINTF
110 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
111 #endif
113 /*
114 *
115 * Standard Values
116 *
117 */
119 #define OK 0
120 #define ERROR -1
122 #define TRUE 1
123 #define FALSE 0
125 #define STATE_CRITICAL 2 /* service state return codes */
126 #define STATE_WARNING 1
127 #define STATE_OK 0
128 #define STATE_UNKNOWN 3
129 #define STATE_DEPENDENT 4
131 #define DEFAULT_SOCKET_TIMEOUT 10 /* timeout after 10 seconds */
133 #define MAX_INPUT_BUFFER 1024 /* max size of most buffers we use */
135 #define MAX_HOST_ADDRESS_LENGTH 256 /* max size of a host address */
138 #ifndef HAVE_SNPRINTF
139 /*
140 int snprintf (char *str, size_t n, const char *fmt, ...);
141 int snprintf (char *str, size_t n, const char *fmt, ...)
142 {
143 char *buf;
144 int i;
145 int j=0;
146 va_list ap;
147 int d;
148 char c, *p, *s;
150 if((buf=malloc(n))==NULL){
151 puts("could not malloc snprintf buffer\n");
152 exit(-1);
153 }
154 va_start(ap,fmt);
155 i=strlen(fmt);
156 while((jj=index(&fmt[j],'%'))){
157 j+=jj+1;
158 switch fmt[j]
159 {
160 case 's':
161 s = va_arg(ap, char *);
162 i+=strlen(s);
163 break;
164 case 'd':
165 d = va_arg(ap, int);
166 i++;
167 if (d<0) i++;
168 while((d=d/10)>0) i++;
169 break;
170 case 'c':
171 c = va_arg(ap, char);
172 i++;
173 break;
174 }
175 }
176 va_end(ap);
177 vsprintf(buf,fmt,ap);
178 strcpy(str,buf[1:n-1]);
179 exit(result);
180 }
181 */
182 #endif