Fix Debian bug #307905: Incorrect usage output
[monitoring-plugins.git] / plugins / netutils.h
blob572a3ae2253c9417bd2d764b372387213cc2f17a
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 * Description:
11 * This file contains common include files and function definitions
12 * used in many of the plugins.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 *****************************************************************************/
31 #ifndef _NETUTILS_H_
32 #define _NETUTILS_H_
34 #include "common.h"
35 #include "utils.h"
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 #include <netdb.h>
40 #ifdef HAVE_SYS_UN_H
41 # include <sys/un.h>
42 # ifndef UNIX_PATH_MAX
43 /* linux uses this, on sun it's hard-coded at 108 without a define */
44 # define UNIX_PATH_MAX 108
45 # endif /* UNIX_PATH_MAX */
46 #endif /* HAVE_SYS_UN_H */
48 /* process_request and wrapper macros */
49 #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
50 process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
51 #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
52 process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
53 int process_tcp_request2 (const char *address, int port,
54 const char *sbuffer, char *rbuffer, int rsize);
55 int process_request (const char *address, int port, int proto,
56 const char *sbuffer, char *rbuffer, int rsize);
58 /* my_connect and wrapper macros */
59 #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
60 #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
61 int np_net_connect(const char *address, int port, int *sd, int proto);
63 /* send_request and wrapper macros */
64 #define send_tcp_request(s, sbuf, rbuf, rsize) \
65 send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
66 #define send_udp_request(s, sbuf, rbuf, rsize) \
67 send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
68 int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
71 /* "is_*" wrapper macros and functions */
72 int is_host (const char *);
73 int is_addr (const char *);
74 int resolve_host_or_addr (const char *, int);
75 void host_or_die(const char *str);
76 #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
77 #ifdef USE_IPV6
78 # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
79 # define is_hostname(addr) resolve_host_or_addr(addr, address_family)
80 #else
81 # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
82 #endif
84 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
85 extern unsigned int socket_timeout;
86 extern int socket_timeout_state;
87 RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
88 #else
89 unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
90 unsigned int socket_timeout_state = STATE_CRITICAL;
91 extern RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
92 #endif
94 extern int econn_refuse_state;
95 extern int was_refused;
96 extern int address_family;
98 /* SSL-Related functionality */
99 #ifdef HAVE_SSL
100 /* maybe this could be merged with the above np_net_connect, via some flags */
101 int np_net_ssl_init(int sd);
102 int np_net_ssl_init_with_hostname(int sd, char *host_name);
103 void np_net_ssl_cleanup();
104 int np_net_ssl_write(const void *buf, int num);
105 int np_net_ssl_read(void *buf, int num);
106 int np_net_ssl_check_cert(int days_till_exp);
107 #endif /* HAVE_SSL */
109 #endif /* _NETUTILS_H_ */