netutils.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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:
  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 _NETUTILS_H_
  31. #define _NETUTILS_H_
  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 108
  42. # endif /* UNIX_PATH_MAX */
  43. #endif /* HAVE_SYS_UN_H */
  44. RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
  45. /* process_request and wrapper macros */
  46. #define process_tcp_request(addr, port, sbuf, rbuf, rsize) \
  47. process_request(addr, port, IPPROTO_TCP, sbuf, rbuf, rsize)
  48. #define process_udp_request(addr, port, sbuf, rbuf, rsize) \
  49. process_request(addr, port, IPPROTO_UDP, sbuf, rbuf, rsize)
  50. int process_tcp_request2 (const char *address, int port,
  51. const char *sbuffer, char *rbuffer, int rsize);
  52. int process_request (const char *address, int port, int proto,
  53. const char *sbuffer, char *rbuffer, int rsize);
  54. /* my_connect and wrapper macros */
  55. #define my_tcp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_TCP)
  56. #define my_udp_connect(addr, port, s) np_net_connect(addr, port, s, IPPROTO_UDP)
  57. int np_net_connect(const char *address, int port, int *sd, int proto);
  58. /* send_request and wrapper macros */
  59. #define send_tcp_request(s, sbuf, rbuf, rsize) \
  60. send_request(s, IPPROTO_TCP, sbuf, rbuf, rsize)
  61. #define send_udp_request(s, sbuf, rbuf, rsize) \
  62. send_request(s, IPPROTO_UDP, sbuf, rbuf, rsize)
  63. int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
  64. /* "is_*" wrapper macros and functions */
  65. int is_host (const char *);
  66. int is_addr (const char *);
  67. int resolve_host_or_addr (const char *, int);
  68. void host_or_die(const char *str);
  69. #define is_inet_addr(addr) resolve_host_or_addr(addr, AF_INET)
  70. #ifdef USE_IPV6
  71. # define is_inet6_addr(addr) resolve_host_or_addr(addr, AF_INET6)
  72. # define is_hostname(addr) resolve_host_or_addr(addr, address_family)
  73. #else
  74. # define is_hostname(addr) resolve_host_or_addr(addr, AF_INET)
  75. #endif
  76. extern unsigned int socket_timeout;
  77. extern int econn_refuse_state;
  78. extern int was_refused;
  79. extern int address_family;
  80. /* SSL-Related functionality */
  81. #ifdef HAVE_SSL
  82. /* maybe this could be merged with the above np_net_connect, via some flags */
  83. int np_net_ssl_init(int sd);
  84. void np_net_ssl_cleanup();
  85. int np_net_ssl_write(const void *buf, int num);
  86. int np_net_ssl_read(void *buf, int num);
  87. int np_net_ssl_check_cert(int days_till_exp);
  88. #endif /* HAVE_SSL */
  89. #endif /* _NETUTILS_H_ */