Go to the documentation of this file.
4 #include "../src/macros.hpp"
5 #include "../tests/testutil.hpp"
6 #include "../tests/testutil_unity.hpp"
7 #include "../unittests/unittest_resolver_common.hpp"
13 #include <sys/types.h>
14 #include <sys/socket.h>
44 const struct addrinfo *hints_,
47 static const struct dns_lut_t dns_lut[] = {
48 {
"ip.zeromq.org",
"10.100.0.1",
"fdf5:d058:d656::1"},
49 {
"ipv4only.zeromq.org",
"10.100.0.2",
"::ffff:10.100.0.2"},
50 {
"ipv6only.zeromq.org",
NULL,
"fdf5:d058:d656::2"},
52 unsigned lut_len =
sizeof (dns_lut) /
sizeof (dns_lut[0]);
57 bool ipv6 = (hints_->ai_family == AF_INET6);
58 bool no_dns = (hints_->ai_flags & AI_NUMERICHOST) != 0;
59 const char *ip =
NULL;
62 for (
unsigned i = 0;
i < lut_len;
i++) {
63 if (strcmp (dns_lut[
i].hostname, node_) == 0) {
87 ai.ai_flags |= AI_NUMERICHOST;
94 static const char *dummy_interfaces[] = {
100 sizeof (dummy_interfaces) /
sizeof (dummy_interfaces[0]);
102 for (
unsigned i = 0;
i < lut_len;
i++) {
103 if (strcmp (dummy_interfaces[
i], ifname_) == 0) {
123 const char *expected_addr_,
124 uint16_t expected_port_ = 0,
125 uint16_t expected_zone_ = 0,
126 const char *expected_addr_v4_failover_ =
NULL)
129 int family = opts_.
ipv6 () ? AF_INET6 : AF_INET;
137 memset (&addr, 0xba,
sizeof (addr));
139 test_ip_resolver_t resolver (opts_);
141 int rc = resolver.resolve (&addr,
name_);
143 if (expected_addr_ ==
NULL) {
152 expected_zone_, expected_addr_v4_failover_);
156 #define MAKE_TEST_V4V6(_test) \
157 static void _test##_ipv4 () { _test (false); } \
159 static void _test##_ipv6 () { _test (true); }
167 const char *expected = ipv6_ ?
"::" :
"0.0.0.0";
179 const char *expected = ipv6_ ?
"::" :
"0.0.0.0";
227 const char *expected = ipv6_ ?
"::ffff:127.0.0.1" :
"127.0.0.1";
228 const char *fallback = ipv6_ ?
"127.0.0.1" :
NULL;
229 test_resolve (resolver_opts,
"127.0.0.1:0", expected, 0, 0, fallback);
237 test_resolve (resolver_opts,
"1.2.128.129",
"1.2.128.129");
251 test_resolve (resolver_opts,
"255.255.255.255",
"255.255.255.255");
259 test_resolve (resolver_opts,
"[1.2.128.129]",
"1.2.128.129");
313 test_resolve (resolver_opts,
"1.2.128.129:123",
"1.2.128.129", 123);
323 test_resolve (resolver_opts,
"1.2.128.129:0",
"1.2.128.129", 0);
333 test_resolve (resolver_opts,
"1.2.3.4:567bad",
"1.2.3.4", 567);
360 test_resolve (resolver_opts,
"[192.168.1.1]:5555",
"192.168.1.1", 5555);
403 resolver_opts.
ipv6 (
true);
412 resolver_opts.
ipv6 (
true);
414 test_resolve (resolver_opts,
"abcd:1234::1:0:234",
"abcd:1234::1:0:234");
421 resolver_opts.
ipv6 (
true);
430 resolver_opts.
ipv6 (
true);
432 test_resolve (resolver_opts,
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
433 "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
440 resolver_opts.
ipv6 (
true);
449 resolver_opts.
ipv6 (
true);
458 resolver_opts.
ipv6 (
true);
467 resolver_opts.
ipv6 (
true);
478 test_resolve (resolver_opts,
"[1234::1]:80",
"1234::1", 80);
487 test_resolve (resolver_opts,
"[1234::1]:*",
"1234::1", 0);
497 test_resolve (resolver_opts,
"abcd:1234::1:0:234:123",
"abcd:1234::1:0:234",
505 resolver_opts.
ipv6 (
true);
510 test_resolve (resolver_opts,
"11.22.33.44",
"::ffff:11.22.33.44", 0, 0,
520 test_resolve (resolver_opts,
"11.22.33.44:55",
"::ffff:11.22.33.44", 55, 0,
528 resolver_opts.
ipv6 (
true);
530 test_resolve (resolver_opts,
"3000:4:5::1:234%2",
"3000:4:5::1:234", 0, 2);
537 resolver_opts.
ipv6 (
true);
548 test_resolve (resolver_opts,
"3000:4:5::1:234%2:1111",
"3000:4:5::1:234",
556 resolver_opts.
ipv6 (
true);
558 test_resolve (resolver_opts,
"3000:4:5::1:234%eth1",
"3000:4:5::1:234", 0,
568 test_resolve (resolver_opts,
"3000:4:5::1:234%eth0:8080",
"3000:4:5::1:234",
578 test_resolve (resolver_opts,
"[3000:4:5::1:234%eth0]:8080",
579 "3000:4:5::1:234", 8080, 2);
586 resolver_opts.
ipv6 (
true);
597 test_resolve (resolver_opts,
"ip.zeromq.org",
"10.100.0.1");
606 test_resolve (resolver_opts,
"ipv4only.zeromq.org",
"10.100.0.2");
643 test_resolve (resolver_opts,
"ip.zeromq.org:1234",
"10.100.0.1", 1234);
652 test_resolve (resolver_opts,
"ip.zeromq.org",
"fdf5:d058:d656::1");
661 test_resolve (resolver_opts,
"ipv6only.zeromq.org",
"fdf5:d058:d656::2");
681 test_resolve (resolver_opts,
"ipv4only.zeromq.org",
"::ffff:10.100.0.2");
691 test_resolve (resolver_opts,
"fdf5:d058:d656::1",
"fdf5:d058:d656::1");
700 test_resolve (resolver_opts,
"ip.zeromq.org:1234",
"fdf5:d058:d656::1",
710 test_resolve (resolver_opts,
"[ip.zeromq.org]",
"10.100.0.1");
728 test_resolve (resolver_opts,
"[ip.zeromq.org]:22",
"10.100.0.1", 22);
759 test_resolve (resolver_opts,
"ip.zeromq.org%lo0",
"fdf5:d058:d656::1", 0,
771 test_resolve (resolver_opts,
"ip.zeromq.org%lo0:4444",
"fdf5:d058:d656::1",
781 test_resolve (resolver_opts,
"[ip.zeromq.org%lo0]:4444",
782 "fdf5:d058:d656::1", 4444, 1);
785 static void test_addr (
int family_,
const char *addr_,
bool multicast_)
793 resolver_opts.
ipv6 (family_ == AF_INET6);
795 test_ip_resolver_t resolver (resolver_opts);
821 test_addr (AF_INET6,
"ffab::1234",
true);
836 test_addr (AF_INET,
"239.255.255.255",
true);
841 test_addr (AF_INET6,
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
true);
846 test_addr (AF_INET,
"223.255.255.255",
false);
851 test_addr (AF_INET6,
"feff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
false);
868 RUN_TEST (test_bind_any_port0_ipv4);
869 RUN_TEST (test_bind_any_port0_ipv6);
872 RUN_TEST (test_nobind_any_port_ipv4);
873 RUN_TEST (test_nobind_any_port_ipv6);
874 RUN_TEST (test_nobind_addr_anyport_ipv4);
875 RUN_TEST (test_nobind_addr_anyport_ipv6);
876 RUN_TEST (test_nobind_addr_port0_ipv4);
877 RUN_TEST (test_nobind_addr_port0_ipv6);
static void test_addr_multicast_ipv6_max()
#define MAKE_TEST_V4V6(_test)
static void test_dns_ipv6_invalid()
static void test_bind_any(bool ipv6_)
static void test_nobind_any_port(bool ipv6_)
ip_resolver_options_t & ipv6(bool ipv6_)
static void test_parse_ipv4_in_ipv6()
static void test_dns_ipv6_only()
static void test_parse_ipv4_reject_ipv6()
static void test_parse_ipv4_zero()
static void test_dns_ipv4_invalid()
static void test_dns_ipv4_ipv6()
static void test_parse_ipv4_port_ipv6_reject()
static void test_parse_ipv6_brackets_missingr()
static void test_dns_ipv6_port()
static void test_nobind_addr_anyport(bool ipv6_)
void test_dns_deny(bool ipv6_)
static void test_dns_ipv6_ipv4()
static void test_parse_ipv4_port_garbage()
static void test_parse_ipv6_scope_if_port()
void test_dns_ipv6_scope_port()
static void test_parse_ipv6_zero()
static void test_parse_ipv4_port_brackets_bad()
ip_resolver_options_t & bindable(bool bindable_)
static void test_parse_ipv4_wild_brackets_bad()
static void test_nobind_any(bool ipv6_)
void validate_address(int family, const zmq::ip_addr_t *addr_, const char *expected_addr_, uint16_t expected_port_=0, uint16_t expected_zone_=0, const char *expected_addr_v4_failover_=NULL)
static void test_parse_ipv6_scope_if_port_brackets()
static void test_addr_unicast_ipv4()
static void test_parse_ipv4_brackets()
static void test_parse_ipv6_port_nobrackets()
virtual int do_getaddrinfo(const char *node_, const char *service_, const struct addrinfo *hints_, struct addrinfo **res_)
static void test_addr_multicast_ipv4()
static void test_parse_ipv4_brackets_missingl()
static void test_parse_ipv4_port_bad()
static void test_parse_ipv4_port_brackets()
static void test_parse_ipv6_brackets()
static void test_dns_ipv4_simple()
void test_dns_ipv6_scope_port_brackets()
static void test_dns_ipv4_port()
static void test_addr_multicast_ipv4_min()
static void test_nobind_addr_port0(bool ipv6_)
ip_resolver_options_t & allow_dns(bool allow_)
static void test_parse_ipv4_in_ipv6_port()
static void test_parse_ipv4_reject_port()
unsigned int do_if_nametoindex(const char *ifname_) ZMQ_FINAL
static void test_bind_any_port0(bool ipv6_)
static void test_parse_ipv4_port0()
static void test_parse_ipv6_scope_int_port()
static void test_parse_ipv4_reject_any()
#define TEST_ASSERT_EQUAL(expected, actual)
ip_resolver_options_t & expect_port(bool expect_)
static void test_parse_ipv6_brackets_bad()
void test_dns_brackets_port_bad()
static void test_resolve(zmq::ip_resolver_options_t opts_, const char *name_, const char *expected_addr_, uint16_t expected_port_=0, uint16_t expected_zone_=0, const char *expected_addr_v4_failover_=NULL)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
static void test_parse_ipv4_max()
#define TEST_IGNORE_MESSAGE(message)
static void test_parse_ipv6_scope_if()
static void test_parse_ipv6_scope_int()
static void test_parse_ipv4_brackets_missingr()
static void test_parse_ipv6_scope_zero()
bool initialize_network()
static void test_dns_ipv6_simple()
static void test_dns_ipv6_numeric()
static void test_parse_ipv6_simple2()
static void test_parse_ipv6_simple()
void test_dns_ipv6_scope()
int do_getaddrinfo(const char *node_, const char *service_, const struct addrinfo *hints_, struct addrinfo **res_) ZMQ_FINAL
void setup_test_environment(int timeout_seconds_)
static void test_addr_multicast_ipv6_sub()
static void test_addr_unicast_ipv6()
static void test_dns_ipv4_numeric()
static void test_parse_ipv6_port()
bool is_multicast() const
static void test_addr(int family_, const char *addr_, bool multicast_)
static void test_parse_ipv6_scope_badif()
static void test_parse_ipv4_simple()
static void test_parse_ipv6_max()
static void test_parse_ipv4_brackets_bad()
void test_dns_brackets_port()
static void test_addr_multicast_ipv4_over()
static void test_parse_ipv4_port_missing()
static void test_parse_ipv6_port_any()
static void test_parse_ipv4_port_brackets_bad2()
test_ip_resolver_t(zmq::ip_resolver_options_t opts_)
static void test_addr_multicast_ipv4_sub()
void test_dns_brackets_bad()
static void test_addr_multicast_ipv6()
static void test_addr_multicast_ipv6_min()
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
static void test_dns_ipv4_only()
static void test_parse_ipv6_brackets_missingl()
static void test_addr_multicast_ipv4_max()
static void test_parse_ipv4_port()
#define TEST_ASSERT_NULL(pointer)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:00