Code

4c0a563c390dc576a607bddcb83aa5b3298f51fe
[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 * Copyright (c) 2003-2007 Nagios Plugins Development Team
8
9 * Last Modified: $Date$
10
11 * Description:
12
13 * This file contains common include files and function definitions
14 * used in many of the plugins.
15
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 3 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, see <http://www.gnu.org/licenses/>.
29
30 * $Id$
31
32 *****************************************************************************/
34 #ifndef _NETUTILS_H_
35 #define _NETUTILS_H_
37 #include "common.h"
38 #include "utils.h"
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include "getaddrinfo.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 void host_or_die(const char *str);
81 #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
82 #ifdef USE_IPV6
83 #  define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
84 #  define is_hostname(addr) resolve_host_or_addr(addr, address_family)
85 #else
86 #  define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
87 #endif
89 extern unsigned int socket_timeout;
90 extern int econn_refuse_state;
91 extern int was_refused;
92 extern int address_family;
94 /* SSL-Related functionality */
95 #ifdef HAVE_SSL
96 /* maybe this could be merged with the above np_net_connect, via some flags */
97 int np_net_ssl_init(int sd);
98 void np_net_ssl_cleanup();
99 int np_net_ssl_write(const void *buf, int num);
100 int np_net_ssl_read(void *buf, int num);
101 int np_net_ssl_check_cert(int days_till_exp);
102 #endif /* HAVE_SSL */
104 #endif /* _NETUTILS_H_ */