PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/nagios-plugins-1.4.16/plugins/netutils.h

#
C Header | 109 lines | 61 code | 12 blank | 36 comment | 0 complexity | 16b3904dc8eee969530738f3ad42721f MD5 | raw file
Possible License(s): GPL-3.0
  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. /* 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. #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
  76. extern unsigned int socket_timeout;
  77. extern int socket_timeout_state;
  78. RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
  79. #else
  80. unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
  81. unsigned int socket_timeout_state = STATE_CRITICAL;
  82. extern RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
  83. #endif
  84. extern int econn_refuse_state;
  85. extern int was_refused;
  86. extern int address_family;
  87. /* SSL-Related functionality */
  88. #ifdef HAVE_SSL
  89. /* maybe this could be merged with the above np_net_connect, via some flags */
  90. int np_net_ssl_init(int sd);
  91. int np_net_ssl_init_with_hostname(int sd, char *host_name);
  92. void np_net_ssl_cleanup();
  93. int np_net_ssl_write(const void *buf, int num);
  94. int np_net_ssl_read(void *buf, int num);
  95. int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit);
  96. #endif /* HAVE_SSL */
  97. #endif /* _NETUTILS_H_ */