netutils.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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-2014 Nagios Plugins Development Team
  8. *
  9. * Description:
  10. *
  11. * This file contains common include files and function definitions
  12. * used in many of the plugins.
  13. *
  14. *
  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.
  19. *
  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.
  24. *
  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/>.
  27. *
  28. *
  29. *****************************************************************************/
  30. #ifndef NAGIOS_NETUGILS_H_INCLUDED_
  31. #define NAGIOS_NETUGILS_H_INCLUDED_
  32. #include "common.h"
  33. #include "utils.h"
  34. #include <netinet/in.h>
  35. #include <arpa/inet.h>
  36. #include <netdb.h>
  37. #ifdef HAVE_SYS_UN_H
  38. # include <sys/un.h>
  39. # ifndef UNIX_PATH_MAX
  40. /* linux uses this, on sun it's hard-coded at 108 without a define */
  41. # define UNIX_PATH_MAX 104
  42. # endif /* UNIX_PATH_MAX */
  43. #endif /* HAVE_SYS_UN_H */
  44. /* process_request and wrapper macros */
  45. #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
  46. process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
  47. #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
  48. process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
  49. int process_tcp_request2 (const char *address, int port,
  50. const char *sbuffer, char *rbuffer, int rsize);
  51. int process_request (const char *address, int port, int proto,
  52. const char *sbuffer, char *rbuffer, int rsize);
  53. /* my_connect and wrapper macros */
  54. #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
  55. #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
  56. int np_net_connect(const char *address, int port, int *sd, int proto);
  57. /* send_request and wrapper macros */
  58. #define send_tcp_request(s, sbuf, rbuf, rsize) \
  59. send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
  60. #define send_udp_request(s, sbuf, rbuf, rsize) \
  61. send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
  62. int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
  63. /* "is_*" wrapper macros and functions */
  64. int is_host (const char *);
  65. int is_addr (const char *);
  66. int resolve_host_or_addr (const char *, int);
  67. void host_or_die(const char *str);
  68. #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
  69. #ifdef USE_IPV6
  70. # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
  71. # define is_hostname(addr) resolve_host_or_addr(addr, address_family)
  72. #else
  73. # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
  74. #endif
  75. extern int econn_refuse_state;
  76. extern int was_refused;
  77. extern int address_family;
  78. extern char address_length(int address_family);
  79. extern void parse_address_string(int address_family, struct sockaddr_storage *addr, char *address, int size);
  80. RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
  81. /* SSL-Related functionality */
  82. #ifdef HAVE_SSL
  83. # define MP_SSLv2 1
  84. # define MP_SSLv3 2
  85. # define MP_TLSv1 3
  86. # define MP_TLSv1_1 4
  87. # define MP_TLSv1_2 5
  88. # define MP_TLSv1_3 6
  89. # define MP_SSLv2_OR_NEWER 7
  90. # define MP_SSLv3_OR_NEWER 8
  91. # define MP_TLSv1_OR_NEWER 9
  92. # define MP_TLSv1_1_OR_NEWER 10
  93. # define MP_TLSv1_2_OR_NEWER 11
  94. # define MP_TLSv1_3_OR_NEWER 12
  95. /* maybe this could be merged with the above np_net_connect, via some flags */
  96. int np_net_ssl_init(int sd);
  97. int np_net_ssl_init_with_hostname(int sd, char *host_name);
  98. int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int version);
  99. int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey);
  100. void np_net_ssl_cleanup(void);
  101. int np_net_ssl_write(const void *buf, int num);
  102. int np_net_ssl_read(void *buf, int num);
  103. int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit);
  104. int np_net_ssl_check_cert_real(SSL *ssl, int days_till_exp_warn, int days_till_exp_crit);
  105. #endif /* HAVE_SSL */
  106. #endif /* NAGIOS_NETUGILS_H_INCLUDED_ */