9cb4bcbbd8ef91bf825d24357c756078b7793d59
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 /* #ifdef HAVE_GETOPT_H */
70 #include <getopt.h>
71 /* #endif */
73 #include <ctype.h>
76 /*
77 *
78 * Missing Functions
79 *
80 */
82 #ifndef HAVE_STRTOL
83 # define strtol(a,b,c) atol((a))
84 #endif
86 #ifndef HAVE_STRTOUL
87 # define strtoul(a,b,c) (unsigned long)atol((a))
88 #endif
90 /*
91 *
92 * Standard Values
93 *
94 */
96 #define OK 0
97 #define ERROR -1
99 #define TRUE 1
100 #define FALSE 0
102 #define STATE_CRITICAL 2 /* service state return codes */
103 #define STATE_WARNING 1
104 #define STATE_OK 0
105 #define STATE_UNKNOWN -1
106 #define STATE_DEPENDENT -2
108 #define DEFAULT_SOCKET_TIMEOUT 10 /* timeout after 10 seconds */
110 #define MAX_INPUT_BUFFER 1024 /* max size of most buffers we use */
112 #define MAX_HOST_ADDRESS_LENGTH 256 /* max size of a host address */
115 #ifndef HAVE_SNPRINTF
116 /*
117 int snprintf (char *str, size_t n, const char *fmt, ...);
118 int snprintf (char *str, size_t n, const char *fmt, ...)
119 {
120 char *buf;
121 int i;
122 int j=0;
123 va_list ap;
124 int d;
125 char c, *p, *s;
127 if((buf=malloc(n))==NULL){
128 puts("could not malloc snprintf buffer\n");
129 exit(-1);
130 }
131 va_start(ap,fmt);
132 i=strlen(fmt);
133 while((jj=index(&fmt[j],'%'))){
134 j+=jj+1;
135 switch fmt[j]
136 {
137 case 's':
138 s = va_arg(ap, char *);
139 i+=strlen(s);
140 break;
141 case 'd':
142 d = va_arg(ap, int);
143 i++;
144 if (d<0) i++;
145 while((d=d/10)>0) i++;
146 break;
147 case 'c':
148 c = va_arg(ap, char);
149 i++;
150 break;
151 }
152 }
153 va_end(ap);
154 vsprintf(buf,fmt,ap);
155 strcpy(str,buf[1:n-1]);
156 exit(result);
157 }
158 */
159 #endif