2023-06-05 00:16:05 +01:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2018-04-30 16:56:17 +02:00
|
|
|
|
|
|
|
#ifndef __ZMQ_IP_RESOLVER_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_IP_RESOLVER_HPP_INCLUDED__
|
|
|
|
|
|
|
|
#if !defined ZMQ_HAVE_WINDOWS
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2019-03-23 08:04:57 -04:00
|
|
|
#include <netdb.h>
|
2018-04-30 16:56:17 +02:00
|
|
|
#endif
|
|
|
|
|
2019-02-05 08:47:41 +01:00
|
|
|
#include "address.hpp"
|
|
|
|
|
2018-04-30 16:56:17 +02:00
|
|
|
namespace zmq
|
|
|
|
{
|
|
|
|
union ip_addr_t
|
|
|
|
{
|
|
|
|
sockaddr generic;
|
|
|
|
sockaddr_in ipv4;
|
|
|
|
sockaddr_in6 ipv6;
|
2018-05-04 00:00:36 +02:00
|
|
|
|
|
|
|
int family () const;
|
|
|
|
bool is_multicast () const;
|
2018-05-04 11:57:10 +02:00
|
|
|
uint16_t port () const;
|
2018-05-05 00:44:13 +02:00
|
|
|
|
|
|
|
const struct sockaddr *as_sockaddr () const;
|
2019-02-05 08:47:41 +01:00
|
|
|
zmq_socklen_t sockaddr_len () const;
|
2018-05-05 00:44:13 +02:00
|
|
|
|
2018-05-04 11:57:10 +02:00
|
|
|
void set_port (uint16_t);
|
|
|
|
|
2018-05-24 17:58:30 +02:00
|
|
|
static ip_addr_t any (int family_);
|
2018-04-30 16:56:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ip_resolver_options_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ip_resolver_options_t ();
|
|
|
|
|
|
|
|
ip_resolver_options_t &bindable (bool bindable_);
|
|
|
|
ip_resolver_options_t &allow_nic_name (bool allow_);
|
|
|
|
ip_resolver_options_t &ipv6 (bool ipv6_);
|
|
|
|
ip_resolver_options_t &expect_port (bool expect_);
|
|
|
|
ip_resolver_options_t &allow_dns (bool allow_);
|
2019-09-05 16:29:53 +03:00
|
|
|
ip_resolver_options_t &allow_path (bool allow_);
|
2018-04-30 16:56:17 +02:00
|
|
|
|
|
|
|
bool bindable ();
|
|
|
|
bool allow_nic_name ();
|
|
|
|
bool ipv6 ();
|
|
|
|
bool expect_port ();
|
|
|
|
bool allow_dns ();
|
2019-09-05 16:29:53 +03:00
|
|
|
bool allow_path ();
|
2018-04-30 16:56:17 +02:00
|
|
|
|
|
|
|
private:
|
2018-05-27 11:10:39 +02:00
|
|
|
bool _bindable_wanted;
|
|
|
|
bool _nic_name_allowed;
|
|
|
|
bool _ipv6_wanted;
|
|
|
|
bool _port_expected;
|
|
|
|
bool _dns_allowed;
|
2019-09-05 16:29:53 +03:00
|
|
|
bool _path_allowed;
|
2018-04-30 16:56:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ip_resolver_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ip_resolver_t (ip_resolver_options_t opts_);
|
2020-02-28 17:49:12 +01:00
|
|
|
virtual ~ip_resolver_t (){};
|
2018-04-30 16:56:17 +02:00
|
|
|
|
|
|
|
int resolve (ip_addr_t *ip_addr_, const char *name_);
|
|
|
|
|
|
|
|
protected:
|
2018-05-30 10:03:55 +02:00
|
|
|
// Virtual functions that are overridden in tests
|
|
|
|
virtual int do_getaddrinfo (const char *node_,
|
|
|
|
const char *service_,
|
|
|
|
const struct addrinfo *hints_,
|
|
|
|
struct addrinfo **res_);
|
|
|
|
|
|
|
|
virtual void do_freeaddrinfo (struct addrinfo *res_);
|
|
|
|
|
|
|
|
virtual unsigned int do_if_nametoindex (const char *ifname_);
|
|
|
|
|
|
|
|
private:
|
2018-05-27 11:10:39 +02:00
|
|
|
ip_resolver_options_t _options;
|
2018-04-30 16:56:17 +02:00
|
|
|
|
|
|
|
int resolve_nic_name (ip_addr_t *ip_addr_, const char *nic_);
|
|
|
|
int resolve_getaddrinfo (ip_addr_t *ip_addr_, const char *addr_);
|
|
|
|
|
|
|
|
#if defined ZMQ_HAVE_WINDOWS
|
2018-05-24 17:58:30 +02:00
|
|
|
int get_interface_name (unsigned long index_, char **dest_) const;
|
|
|
|
int wchar_to_utf8 (const WCHAR *src_, char **dest_) const;
|
2018-04-30 16:56:17 +02:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|