1 /*****************************************************************************
3 * Nagios plugins net utilities include file
6 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
7 * Copyright (c) 2003-2007 Nagios Plugins Development Team
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 *****************************************************************************/
36 #include <netinet/in.h>
37 #include <arpa/inet.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 RETSIGTYPE
socket_timeout_alarm_handler (int) __attribute__((noreturn
));
50 /* process_request and wrapper macros */
51 #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
52 process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
53 #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
54 process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
55 int process_tcp_request2 (const char *address
, int port
,
56 const char *sbuffer
, char *rbuffer
, int rsize
);
57 int process_request (const char *address
, int port
, int proto
,
58 const char *sbuffer
, char *rbuffer
, int rsize
);
60 /* my_connect and wrapper macros */
61 #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
62 #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
63 int np_net_connect(const char *address
, int port
, int *sd
, int proto
);
65 /* send_request and wrapper macros */
66 #define send_tcp_request(s, sbuf, rbuf, rsize) \
67 send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
68 #define send_udp_request(s, sbuf, rbuf, rsize) \
69 send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
70 int send_request (int sd
, int proto
, const char *send_buffer
, char *recv_buffer
, int recv_size
);
73 /* "is_*" wrapper macros and functions */
74 int is_host (const char *);
75 int is_addr (const char *);
76 int resolve_host_or_addr (const char *, int);
77 void host_or_die(const char *str
);
78 #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
80 # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
81 # define is_hostname(addr) resolve_host_or_addr(addr, address_family)
83 # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
86 extern unsigned int socket_timeout
;
87 extern int econn_refuse_state
;
88 extern int was_refused
;
89 extern int address_family
;
91 /* SSL-Related functionality */
93 /* maybe this could be merged with the above np_net_connect, via some flags */
94 int np_net_ssl_init(int sd
);
95 void np_net_ssl_cleanup();
96 int np_net_ssl_write(const void *buf
, int num
);
97 int np_net_ssl_read(void *buf
, int num
);
98 int np_net_ssl_check_cert(int days_till_exp
);
101 #endif /* _NETUTILS_H_ */