Code

- added code to allow check_tcp (via np_net_connect) work with local
[nagiosplug.git] / plugins / netutils.h
1 /******************************************************************************
2 *
3 * Nagios plugins net utilities include file
4 *
5 * License: GPL
6 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
7 *
8 * Last Modified: $Date$
9 *
10 * Description:
11 *
12 * This file contains common include files and function definitions
13 * used in many of 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 * $Id$
32 *
33 ******************************************************************************/
35 #ifndef _NETUTILS_H_
36 #define _NETUTILS_H_
38 #include "config.h"
39 #include "common.h"
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
43 #ifdef HAVE_SYS_UN_H
44 # include <sys/un.h>
45 # ifndef UNIX_PATH_MAX
46    /* linux uses this, on sun it's hard-coded at 108 without a define */
47 #  define UNIX_PATH_MAX 108
48 # endif /* UNIX_PATH_MAX */
49 #endif /* HAVE_SYS_UN_H */
51 RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
53 /* process_request and wrapper macros */
54 #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
55         process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
56 #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
57         process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
58 int process_tcp_request2 (const char *address, int port,
59   const char *sbuffer, char *rbuffer, int rsize);
60 int process_request (const char *address, int port, int proto,
61   const char *sbuffer, char *rbuffer, int rsize);
63 /* my_connect and wrapper macros */
64 #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
65 #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
66 int np_net_connect(const char *address, int port, int *sd, int proto);
68 /* send_request and wrapper macros */
69 #define send_tcp_request(s, sbuf, rbuf, rsize) \
70         send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
71 #define send_udp_request(s, sbuf, rbuf, rsize) \
72         send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
73 int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
76 /* "is_*" wrapper macros and functions */
77 int is_host (const char *);
78 int is_addr (const char *);
79 int resolve_host_or_addr (const char *, int);
80 #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
81 #ifdef USE_IPV6
82 #  define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
83 #  define is_hostname(addr) resolve_host_or_addr(addr, address_family)
84 #else
85 #  define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
86 #endif
88 extern unsigned int socket_timeout;
89 extern int econn_refuse_state;
90 extern int was_refused;
91 extern int address_family;
93 /* SSL-Related functionality */
94 #ifdef HAVE_SSL
95 /* maybe this could be merged with the above np_net_connect, via some flags */
96 int np_net_ssl_init(int sd);
97 void np_net_ssl_cleanup();
98 int np_net_ssl_write(const void *buf, int num);
99 int np_net_ssl_read(void *buf, int num);
100 int np_net_ssl_check_cert(int days_till_exp);
101 #endif /* HAVE_SSL */
103 #endif /* _NETUTILS_H_ */