mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Problem: test_radio_dish triggers aliasing errors with some compilers
Solution: refactor the test code to work around aliasing issues
This commit is contained in:
parent
21f642fa4f
commit
4eb6786347
@ -268,6 +268,13 @@ static const char *mcast_url (int ipv6_)
|
|||||||
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
|
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
union sa_u
|
||||||
|
{
|
||||||
|
struct sockaddr generic;
|
||||||
|
struct sockaddr_in ipv4;
|
||||||
|
struct sockaddr_in6 ipv6;
|
||||||
|
};
|
||||||
|
|
||||||
// Test if multicast is available on this machine by attempting to
|
// Test if multicast is available on this machine by attempting to
|
||||||
// send a receive a multicast datagram
|
// send a receive a multicast datagram
|
||||||
static bool is_multicast_available (int ipv6_)
|
static bool is_multicast_available (int ipv6_)
|
||||||
@ -279,14 +286,14 @@ static bool is_multicast_available (int ipv6_)
|
|||||||
bool success = false;
|
bool success = false;
|
||||||
const char *msg = "it works";
|
const char *msg = "it works";
|
||||||
char buf[32];
|
char buf[32];
|
||||||
struct sockaddr_storage any;
|
union sa_u any;
|
||||||
struct sockaddr_storage mcast;
|
union sa_u mcast;
|
||||||
socklen_t sl;
|
socklen_t sl;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (ipv6_) {
|
if (ipv6_) {
|
||||||
struct sockaddr_in6 *any_ipv6 = (struct sockaddr_in6 *) &any;
|
struct sockaddr_in6 *any_ipv6 = &any.ipv6;
|
||||||
struct sockaddr_in6 *mcast_ipv6 = (struct sockaddr_in6 *) &mcast;
|
struct sockaddr_in6 *mcast_ipv6 = &mcast.ipv6;
|
||||||
|
|
||||||
any_ipv6->sin6_family = AF_INET6;
|
any_ipv6->sin6_family = AF_INET6;
|
||||||
any_ipv6->sin6_port = htons (port);
|
any_ipv6->sin6_port = htons (port);
|
||||||
@ -307,8 +314,8 @@ static bool is_multicast_available (int ipv6_)
|
|||||||
|
|
||||||
sl = sizeof (*any_ipv6);
|
sl = sizeof (*any_ipv6);
|
||||||
} else {
|
} else {
|
||||||
struct sockaddr_in *any_ipv4 = (struct sockaddr_in *) &any;
|
struct sockaddr_in *any_ipv4 = &any.ipv4;
|
||||||
struct sockaddr_in *mcast_ipv4 = (struct sockaddr_in *) &mcast;
|
struct sockaddr_in *mcast_ipv4 = &mcast.ipv4;
|
||||||
|
|
||||||
any_ipv4->sin_family = AF_INET;
|
any_ipv4->sin_family = AF_INET;
|
||||||
any_ipv4->sin_port = htons (5555);
|
any_ipv4->sin_port = htons (5555);
|
||||||
@ -338,14 +345,14 @@ static bool is_multicast_available (int ipv6_)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = bind (bind_sock, (struct sockaddr *) &any, sl);
|
rc = bind (bind_sock, &any.generic, sl);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipv6_) {
|
if (ipv6_) {
|
||||||
struct ipv6_mreq mreq;
|
struct ipv6_mreq mreq;
|
||||||
struct sockaddr_in6 *mcast_ipv6 = (struct sockaddr_in6 *) &mcast;
|
struct sockaddr_in6 *mcast_ipv6 = &mcast.ipv6;
|
||||||
|
|
||||||
mreq.ipv6mr_multiaddr = mcast_ipv6->sin6_addr;
|
mreq.ipv6mr_multiaddr = mcast_ipv6->sin6_addr;
|
||||||
mreq.ipv6mr_interface = 0;
|
mreq.ipv6mr_interface = 0;
|
||||||
@ -364,7 +371,7 @@ static bool is_multicast_available (int ipv6_)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
struct ip_mreq mreq;
|
struct ip_mreq mreq;
|
||||||
struct sockaddr_in *mcast_ipv4 = (struct sockaddr_in *) &mcast;
|
struct sockaddr_in *mcast_ipv4 = &mcast.ipv4;
|
||||||
|
|
||||||
mreq.imr_multiaddr = mcast_ipv4->sin_addr;
|
mreq.imr_multiaddr = mcast_ipv4->sin_addr;
|
||||||
mreq.imr_interface.s_addr = htonl (INADDR_ANY);
|
mreq.imr_interface.s_addr = htonl (INADDR_ANY);
|
||||||
@ -385,8 +392,7 @@ static bool is_multicast_available (int ipv6_)
|
|||||||
|
|
||||||
msleep (SETTLE_TIME);
|
msleep (SETTLE_TIME);
|
||||||
|
|
||||||
rc =
|
rc = sendto (send_sock, msg, strlen (msg), 0, &mcast.generic, sl);
|
||||||
sendto (send_sock, msg, strlen (msg), 0, (struct sockaddr *) &mcast, sl);
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user