Problem: address parsing code is tied to the TCP code

Solution: Factor the code into a different file with a well defined API and add
unit tests.
This commit is contained in:
Lionel Flandrin
2018-04-30 16:56:17 +02:00
parent 6160da5dbe
commit 4cd2c2ebf8
9 changed files with 1731 additions and 659 deletions

View File

@@ -35,6 +35,8 @@
#include <netinet/in.h>
#endif
#include "ip_resolver.hpp"
namespace zmq
{
class tcp_address_t
@@ -48,8 +50,7 @@ class tcp_address_t
// structure. If 'local' is true, names are resolved as local interface
// names. If it is false, names are resolved as remote hostnames.
// If 'ipv6' is true, the name may resolve to IPv6 address.
int
resolve (const char *name_, bool local_, bool ipv6_, bool is_src_ = false);
int resolve (const char *name_, bool local_, bool ipv6_);
// The opposite to resolve()
virtual int to_string (std::string &addr_);
@@ -67,31 +68,8 @@ class tcp_address_t
bool has_src_addr () const;
protected:
int resolve_nic_name (const char *nic_, bool ipv6_, bool is_src_ = false);
int resolve_interface (const char *interface_,
bool ipv6_,
bool is_src_ = false);
int
resolve_hostname (const char *hostname_, bool ipv6_, bool is_src_ = false);
#if defined ZMQ_HAVE_WINDOWS
int get_interface_name (unsigned long index, char **dest) const;
int wchar_to_utf8 (const WCHAR *src, char **dest) const;
#endif
union
{
sockaddr generic;
sockaddr_in ipv4;
sockaddr_in6 ipv6;
} address;
union
{
sockaddr generic;
sockaddr_in ipv4;
sockaddr_in6 ipv6;
} source_address;
ip_addr_t address;
ip_addr_t source_address;
bool _has_src_addr;
};