Back to index

nagios-plugins  1.4.16
netutils.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * 
00003 * Nagios plugins net utilities 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 function definitions
00012 * used in many of 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 _NETUTILS_H_
00032 #define _NETUTILS_H_
00033 
00034 #include "common.h"
00035 #include "utils.h"
00036 #include <netinet/in.h>
00037 #include <arpa/inet.h>
00038 #include <netdb.h>
00039 
00040 #ifdef HAVE_SYS_UN_H
00041 # include <sys/un.h>
00042 # ifndef UNIX_PATH_MAX
00043    /* linux uses this, on sun it's hard-coded at 108 without a define */
00044 #  define UNIX_PATH_MAX 108
00045 # endif /* UNIX_PATH_MAX */
00046 #endif /* HAVE_SYS_UN_H */
00047 
00048 /* process_request and wrapper macros */
00049 #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
00050        process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
00051 #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
00052        process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
00053 int process_tcp_request2 (const char *address, int port,
00054   const char *sbuffer, char *rbuffer, int rsize);
00055 int process_request (const char *address, int port, int proto,
00056   const char *sbuffer, char *rbuffer, int rsize);
00057 
00058 /* my_connect and wrapper macros */
00059 #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
00060 #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
00061 int np_net_connect(const char *address, int port, int *sd, int proto);
00062 
00063 /* send_request and wrapper macros */
00064 #define send_tcp_request(s, sbuf, rbuf, rsize) \
00065        send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
00066 #define send_udp_request(s, sbuf, rbuf, rsize) \
00067        send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
00068 int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
00069 
00070 
00071 /* "is_*" wrapper macros and functions */
00072 int is_host (const char *);
00073 int is_addr (const char *);
00074 int resolve_host_or_addr (const char *, int);
00075 void host_or_die(const char *str);
00076 #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
00077 #ifdef USE_IPV6
00078 #  define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
00079 #  define is_hostname(addr) resolve_host_or_addr(addr, address_family)
00080 #else
00081 #  define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
00082 #endif
00083 
00084 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
00085 extern unsigned int socket_timeout;
00086 extern int socket_timeout_state;
00087 RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
00088 #else
00089 unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
00090 unsigned int socket_timeout_state = STATE_CRITICAL;
00091 extern RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
00092 #endif
00093 
00094 extern int econn_refuse_state;
00095 extern int was_refused;
00096 extern int address_family;
00097 
00098 /* SSL-Related functionality */
00099 #ifdef HAVE_SSL
00100 /* maybe this could be merged with the above np_net_connect, via some flags */
00101 int np_net_ssl_init(int sd);
00102 int np_net_ssl_init_with_hostname(int sd, char *host_name);
00103 void np_net_ssl_cleanup();
00104 int np_net_ssl_write(const void *buf, int num);
00105 int np_net_ssl_read(void *buf, int num);
00106 int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit);
00107 #endif /* HAVE_SSL */
00108 
00109 #endif /* _NETUTILS_H_ */