1 /******************************************************************************
3 * Nagios plugins net utilities include file
6 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
8 * Last Modified: $Date$
12 * This file contains common include files and function definitions
13 * used in many of the plugins.
15 * License Information:
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.
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.
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.
33 ******************************************************************************/
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
42 #include "getaddrinfo.h"
46 # ifndef UNIX_PATH_MAX
47 /* linux uses this, on sun it's hard-coded at 108 without a define */
48 # define UNIX_PATH_MAX 108
49 # endif /* UNIX_PATH_MAX */
50 #endif /* HAVE_SYS_UN_H */
52 RETSIGTYPE
socket_timeout_alarm_handler (int) __attribute__((noreturn
));
54 /* process_request and wrapper macros */
55 #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
56 process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
57 #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
58 process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
59 int process_tcp_request2 (const char *address
, int port
,
60 const char *sbuffer
, char *rbuffer
, int rsize
);
61 int process_request (const char *address
, int port
, int proto
,
62 const char *sbuffer
, char *rbuffer
, int rsize
);
64 /* my_connect and wrapper macros */
65 #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
66 #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
67 int np_net_connect(const char *address
, int port
, int *sd
, int proto
);
69 /* send_request and wrapper macros */
70 #define send_tcp_request(s, sbuf, rbuf, rsize) \
71 send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
72 #define send_udp_request(s, sbuf, rbuf, rsize) \
73 send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
74 int send_request (int sd
, int proto
, const char *send_buffer
, char *recv_buffer
, int recv_size
);
77 /* "is_*" wrapper macros and functions */
78 int is_host (const char *);
79 int is_addr (const char *);
80 int resolve_host_or_addr (const char *, int);
81 void host_or_die(const char *str
);
82 #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
84 # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
85 # define is_hostname(addr) resolve_host_or_addr(addr, address_family)
87 # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
90 extern unsigned int socket_timeout
;
91 extern int econn_refuse_state
;
92 extern int was_refused
;
93 extern int address_family
;
95 /* SSL-Related functionality */
97 /* maybe this could be merged with the above np_net_connect, via some flags */
98 int np_net_ssl_init(int sd
);
99 void np_net_ssl_cleanup();
100 int np_net_ssl_write(const void *buf
, int num
);
101 int np_net_ssl_read(void *buf
, int num
);
102 int np_net_ssl_check_cert(int days_till_exp
);
103 #endif /* HAVE_SSL */
105 #endif /* _NETUTILS_H_ */