~ubuntu-branches/ubuntu/precise/nagios-plugins/precise-proposed

« back to all changes in this revision

Viewing changes to plugins/common.h.in

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2004-06-15 15:37:48 UTC
  • Revision ID: james.westby@ubuntu.com-20040615153748-pq7702qdzghqfcns
Tags: upstream-1.3.1.0
ImportĀ upstreamĀ versionĀ 1.3.1.0

Show diffs side-by-side

added added

removed removed

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