Back to index

nagios-plugins  1.4.16
common.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * 
00003 * Nagios plugins common include file
00004 * 
00005 * License: GPL
00006 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
00007 * Copyright (c) 2003-2007 Nagios Plugins Development Team
00008 * 
00009 * Description:
00010 * 
00011 * This file contains common include files and defines used in many of
00012 * the plugins.
00013 * 
00014 * 
00015 * This program is free software: you can redistribute it and/or modify
00016 * it under the terms of the GNU General Public License as published by
00017 * the Free Software Foundation, either version 3 of the License, or
00018 * (at your option) any later version.
00019 * 
00020 * This program is distributed in the hope that it will be useful,
00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 * GNU General Public License for more details.
00024 * 
00025 * You should have received a copy of the GNU General Public License
00026 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00027 * 
00028 * 
00029 *****************************************************************************/
00030 
00031 #ifndef _COMMON_H_
00032 #define _COMMON_H_
00033 
00034 #include "config.h"
00035 
00036 #ifdef HAVE_FEATURES_H
00037 #include <features.h>
00038 #endif
00039 
00040 #include <stdio.h>                                             /* obligatory includes */
00041 #include <stdlib.h>
00042 #include <errno.h>
00043 
00044 /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
00045 #if HAVE_INTTYPES_H
00046 # include <inttypes.h>
00047 #endif
00048 #if HAVE_STDINT_H
00049 # include <stdint.h>
00050 #endif
00051 #include <unistd.h>
00052 #ifndef UINTMAX_MAX
00053 # define UINTMAX_MAX ((uintmax_t) -1)
00054 #endif
00055 
00056 #include <limits.h>  /* This is assumed true, because coreutils assume it too */
00057 
00058 #ifdef HAVE_MATH_H
00059 #include <math.h>
00060 #endif
00061 
00062 #ifdef _AIX
00063 #ifdef HAVE_MP_H
00064 #include <mp.h>
00065 #endif
00066 #endif
00067 
00068 #ifdef HAVE_STRINGS_H
00069 #include <strings.h>
00070 #endif
00071 #ifdef HAVE_STRING_H
00072 #include <string.h>
00073 #endif
00074 
00075 #ifdef HAVE_UNISTD_H
00076 #include <unistd.h>
00077 #endif
00078 
00079 /* GET_NUMBER_OF_CPUS is a macro to return 
00080    number of CPUs, if we can get that data.
00081    Use configure.in to test for various OS ways of
00082    getting that data
00083    Will return -1 if cannot get data
00084 */
00085 #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF 
00086 #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
00087 #else
00088 #define GET_NUMBER_OF_CPUS() -1
00089 #endif
00090 
00091 #ifdef TIME_WITH_SYS_TIME
00092 # include <sys/time.h>
00093 # include <time.h>
00094 #else
00095 # ifdef HAVE_SYS_TIME_H
00096 #  include <sys/time.h>
00097 # else
00098 #  include <time.h>
00099 # endif
00100 #endif
00101 
00102 #ifdef HAVE_SYS_TYPES_H
00103 #include <sys/types.h>
00104 #endif
00105 
00106 #ifdef HAVE_SYS_SOCKET_H
00107 #include <sys/socket.h>
00108 #endif
00109 
00110 #ifdef HAVE_SIGNAL_H
00111 #include <signal.h>
00112 #endif
00113 
00114 /* GNU Libraries */
00115 #include <getopt.h>
00116 #include "dirname.h"
00117 
00118 #ifdef HAVE_LOCALE_H
00119 #include <locale.h>
00120 #endif
00121 
00122 #ifdef HAVE_SYS_POLL_H
00123 # include "sys/poll.h"
00124 #endif
00125 
00126 /*
00127  *
00128  * Missing Functions
00129  *
00130  */
00131 
00132 #ifndef HAVE_STRTOL
00133 # define strtol(a,b,c) atol((a))
00134 #endif
00135 
00136 #ifndef HAVE_STRTOUL
00137 # define strtoul(a,b,c) (unsigned long)atol((a))
00138 #endif
00139 
00140 /* SSL implementations */
00141 #ifdef HAVE_GNUTLS_OPENSSL_H
00142 #  include <gnutls/openssl.h>
00143 #else
00144 #  ifdef HAVE_SSL_H
00145 #    include <rsa.h>
00146 #    include <crypto.h>
00147 #    include <x509.h>
00148 #    include <pem.h>
00149 #    include <ssl.h>
00150 #    include <err.h>
00151 #  else
00152 #    ifdef HAVE_OPENSSL_SSL_H
00153 #      include <openssl/rsa.h>
00154 #      include <openssl/crypto.h>
00155 #      include <openssl/x509.h>
00156 #      include <openssl/pem.h>
00157 #      include <openssl/ssl.h>
00158 #      include <openssl/err.h>
00159 #    endif
00160 #  endif
00161 #endif
00162 
00163 /*
00164  *
00165  * Standard Values
00166  *
00167  */
00168 
00169 enum {
00170        OK = 0,
00171        ERROR = -1
00172 };
00173 
00174 /* AIX seems to have this defined somewhere else */
00175 #ifndef FALSE
00176 enum {
00177        FALSE,
00178        TRUE
00179 };
00180 #endif
00181 
00182 enum {
00183        STATE_OK,
00184        STATE_WARNING,
00185        STATE_CRITICAL,
00186        STATE_UNKNOWN,
00187        STATE_DEPENDENT
00188 };
00189 
00190 enum {
00191        DEFAULT_SOCKET_TIMEOUT = 10,        /* timeout after 10 seconds */
00192        MAX_INPUT_BUFFER = 8192,         /* max size of most buffers we use */
00193        MAX_HOST_ADDRESS_LENGTH = 256       /* max size of a host address */
00194 };
00195 
00196 /*
00197  *
00198  * Internationalization
00199  *
00200  */
00201 #include "gettext.h"
00202 #define _(String) gettext (String)
00203 #if ! ENABLE_NLS
00204 # undef textdomain
00205 # define textdomain(Domainname) /* empty */
00206 # undef bindtextdomain
00207 # define bindtextdomain(Domainname, Dirname) /* empty */
00208 #endif
00209 
00210 /* For non-GNU compilers to ignore __attribute__ */
00211 #ifndef __GNUC__
00212 # define __attribute__(x) /* do nothing */
00213 #endif
00214 
00215 #endif /* _COMMON_H_ */