Go to the documentation of this file.
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
16 #define MAKE_TEST_V4V6(_test) \
17 static void _test##_ipv4 () \
22 static void _test##_ipv6 () \
24 if (!is_ipv6_available ()) { \
25 TEST_IGNORE_MESSAGE ("ipv6 is not available"); \
35 const size_t len = strlen (body_);
52 const size_t len = strlen (body_);
86 char group[19] =
"0123456789ABCDEFGH";
111 too_long_group[
index] =
'A';
206 const char *
url = ipv6_ ?
"udp://[::1]:5556" :
"udp://127.0.0.1:5556";
241 const char *radio_url = ipv6_ ?
"udp://[::1]:5556" :
"udp://127.0.0.1:5556";
258 #define MCAST_IPV4 "226.8.5.5"
259 #define MCAST_IPV6 "ff02::7a65:726f:6df1:0a01"
270 #ifndef IPV6_ADD_MEMBERSHIP
271 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
285 int family = ipv6_ ? AF_INET6 : AF_INET;
289 bool success =
false;
290 const char *msg =
"it works";
298 struct sockaddr_in6 *any_ipv6 = &any.
ipv6;
299 struct sockaddr_in6 *mcast_ipv6 = &mcast.
ipv6;
301 any_ipv6->sin6_family = AF_INET6;
302 any_ipv6->sin6_port = htons (port);
303 any_ipv6->sin6_flowinfo = 0;
304 any_ipv6->sin6_scope_id = 0;
311 *mcast_ipv6 = *any_ipv6;
318 sl =
sizeof (*any_ipv6);
320 struct sockaddr_in *any_ipv4 = &any.
ipv4;
321 struct sockaddr_in *mcast_ipv4 = &mcast.
ipv4;
323 any_ipv4->sin_family = AF_INET;
324 any_ipv4->sin_port = htons (5555);
331 *mcast_ipv4 = *any_ipv4;
338 sl =
sizeof (*any_ipv4);
341 bind_sock = socket (family, SOCK_DGRAM, IPPROTO_UDP);
346 send_sock = socket (family, SOCK_DGRAM, IPPROTO_UDP);
351 rc = bind (bind_sock, &any.
generic, sl);
357 struct ipv6_mreq mreq;
358 const sockaddr_in6 *
const mcast_ipv6 = &mcast.
ipv6;
360 mreq.ipv6mr_multiaddr = mcast_ipv6->sin6_addr;
361 mreq.ipv6mr_interface = 0;
370 rc = setsockopt (send_sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
377 const sockaddr_in *
const mcast_ipv4 = &mcast.
ipv4;
379 mreq.imr_multiaddr = mcast_ipv4->sin_addr;
380 mreq.imr_interface.s_addr = htonl (INADDR_ANY);
382 rc = setsockopt (bind_sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
389 rc = setsockopt (send_sock, IPPROTO_IP, IP_MULTICAST_LOOP,
398 rc = sendto (send_sock, msg,
static_cast<socklen_t
> (strlen (msg)), 0,
406 rc = recvfrom (bind_sock,
buf,
sizeof (
buf) - 1, 0,
NULL, 0);
413 success = (strcmp (msg,
buf) == 0);
416 if (bind_sock >= 0) {
420 if (send_sock >= 0) {
468 "ZMQ_MULTICAST_LOOP=false does not appear to work on Windows (TODO)");
515 RUN_TEST (test_radio_bind_fails_ipv4);
516 RUN_TEST (test_radio_bind_fails_ipv6);
517 RUN_TEST (test_dish_connect_fails_ipv4);
518 RUN_TEST (test_dish_connect_fails_ipv6);
519 RUN_TEST (test_radio_dish_tcp_poll_ipv4);
520 RUN_TEST (test_radio_dish_tcp_poll_ipv6);
521 RUN_TEST (test_radio_dish_udp_ipv4);
522 RUN_TEST (test_radio_dish_udp_ipv6);
524 RUN_TEST (test_radio_dish_mcast_ipv4);
525 RUN_TEST (test_radio_dish_no_loop_ipv4);
527 RUN_TEST (test_radio_dish_mcast_ipv6);
528 RUN_TEST (test_radio_dish_no_loop_ipv6);
const char * zmq_msg_group(zmq_msg_t *msg_)
#define TEST_ASSERT_EQUAL_STRING(expected, actual)
const void * as_setsockopt_opt_t(const void *opt_)
#define TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len)
static const char * mcast_url(int ipv6_)
void test_leave_unjoined_fails()
int zmq_msg_set_group(zmq_msg_t *msg_, const char *group_)
void msleep(int milliseconds_)
ZMQ_EXPORT int zmq_msg_send(zmq_msg_t *msg_, void *s_, int flags_)
ZMQ_EXPORT int zmq_poll(zmq_pollitem_t *items_, int nitems_, long timeout_)
#define SETUP_TEARDOWN_TESTCONTEXT
void msg_recv_cmp(void *s_, const char *group_, const char *body_)
#define ZMQ_MULTICAST_LOOP
static void test_radio_dish_no_loop(int ipv6_)
static void test_radio_dish_mcast(int ipv6_)
#define ZMQ_GROUP_MAX_LENGTH
ZMQ_EXPORT void * zmq_msg_data(zmq_msg_t *msg_)
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
void test_radio_dish_udp(int ipv6_)
ZMQ_EXPORT int zmq_setsockopt(void *s_, int option_, const void *optval_, size_t optvallen_)
char my_endpoint[MAX_SOCKET_STRING]
#define MAX_SOCKET_STRING
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
void bind_loopback(void *socket_, int ipv6_, char *my_endpoint_, size_t len_)
ZMQ_EXPORT int zmq_msg_recv(zmq_msg_t *msg_, void *s_, int flags_)
void * test_context_socket(int type_)
int zmq_leave(void *s_, const char *group_)
GLenum GLuint GLenum GLsizei const GLchar * buf
#define TEST_ASSERT_EQUAL_INT(expected, actual)
void test_join_too_long_fails()
ZMQ_EXPORT int zmq_msg_init(zmq_msg_t *msg_)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
#define TEST_IGNORE_MESSAGE(message)
int zmq_join(void *s_, const char *group_)
void test_dish_connect_fails(int ipv6_)
ZMQ_EXPORT int zmq_recv(void *s_, void *buf_, size_t len_, int flags_)
void setup_test_environment(int timeout_seconds_)
static bool is_multicast_available(int ipv6_)
int test_inet_pton(int af_, const char *src_, void *dst_)
ZMQ_EXPORT int zmq_msg_init_size(zmq_msg_t *msg_, size_t size_)
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr)
SETUP_TEARDOWN_TESTCONTEXT void msg_send_expect_success(void *s_, const char *group_, const char *body_)
ZMQ_EXPORT void zmq_sleep(int seconds_)
void test_join_twice_fails()
void test_radio_bind_fails(int ipv6_)
static void ignore_if_unavailable(int ipv6_)
void * test_context_socket_close(void *socket_)
void test_radio_dish_tcp_poll(int ipv6_)
static uint32_t * group(tarjan *t, upb_refcounted *r)
ZMQ_EXPORT int zmq_msg_close(zmq_msg_t *msg_)
#define MAKE_TEST_V4V6(_test)
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
#define IPV6_ADD_MEMBERSHIP
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59