The netPath->eventSock is type of SOCK_DGRAM.
But I’m not sure about the multicast group! I have checked with the Wireshark the communication between this two hosts (Ubuntu <—> QNX) if any IGMP messages (these messages register host to multic. group ) are send. Only the Ubuntu host has send IGMP message and has joined the multicast group. But there was no communication from the QNX site, and QNX host didn’t join the multicast group. I was testing Ubuntu <—> Ubuntu connection and both sides joined the group and all was working well.
I post the code where the initialization of the socket is.
Any ideas why multicast group registration in QNX fails??? How to set up the QNX ?
Boolean netInit(NetPath *netPath, RunTimeOpts *rtOpts, PtpClock *ptpClock)
{
int i;
socklen_t temp;
#ifdef QNXNTO
unsigned char tempc;
define temp_value tempc
#else
define temp_value temp
#endif
struct in_addr interfaceAddr, netAddr;
struct sockaddr_in addr;
struct ip_mreq imr;
char addrStr[NET_ADDRESS_LENGTH];
char *s;
DBG(“netInit\n”);
/* open socket */
if( (netPath->eventSock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) ) < 0 ) {
PERROR(“failed to initalize sockets”);
return FALSE;
}
/* find a network interface */
if( !(interfaceAddr.s_addr = findIface(rtOpts->ifaceName, &ptpClock->port_communication_technology,
ptpClock->port_uuid_field, netPath)) )
return FALSE;
temp = 1; /* allow address reuse */
if( setsockopt(netPath->eventSock, SOL_SOCKET, SO_REUSEADDR, &temp, sizeof(int)) < 0 ) {
DBG(“failed to set socket reuse\n”);
}
/* bind sockets /
/ need INADDR_ANY to allow receipt of multi-cast and uni-cast messages */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(PTP_EVENT_PORT);
if(bind(netPath->eventSock, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0){
PERROR(“failed to bind event socket”);
return FALSE;
}
/* set port address */
(Integer16)ptpClock->event_port_address = PTP_EVENT_PORT;
/* resolve PTP subdomain */
if(!lookupSubdomainAddress(rtOpts->subdomainName, addrStr))
return FALSE;
if(!inet_aton(addrStr, &netAddr)) {
ERROR(“failed to encode multi-cast address: %s\n”, addrStr);
return FALSE;
}
netPath->multicastAddr = netAddr.s_addr;
s = addrStr;
for(i = 0; i < SUBDOMAIN_ADDRESS_LENGTH; ++i) {
ptpClock->subdomain_address[i] = strtol(s, &s, 0);
if(!s)
break;
++s;
}
/* multicast send only on specified interface */
imr.imr_multiaddr.s_addr = netAddr.s_addr;
imr.imr_interface.s_addr = interfaceAddr.s_addr;
if( setsockopt(netPath->eventSock, IPPROTO_IP, IP_MULTICAST_IF, &imr.imr_interface.s_addr, sizeof(struct in_addr)) < 0 ) {
PERROR(“failed to enable multi-cast on the interface”);
return FALSE;
}
/* join multicast group (for receiving) on specified interface */
if( setsockopt(netPath->eventSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(struct ip_mreq)) < 0 ) {
PERROR(“failed to join the multi-cast group”);
return FALSE;
}
/* set socket time-to-live to 1 */
temp_value = 1;
if( setsockopt(netPath->eventSock, IPPROTO_IP, IP_MULTICAST_TTL, &temp_value, sizeof(temp_value)) < 0 ) {
PERROR(“failed to set the multi-cast time-to-live”);
return FALSE;
}
/* enable loopback */
temp_value = 1;
if( setsockopt(netPath->eventSock, IPPROTO_IP, IP_MULTICAST_LOOP, &temp_value, sizeof(temp_value)) < 0 ) {
PERROR(“failed to enable multi-cast loopback”);
return FALSE;
}
/* make timestamps available through recvmsg() */
temp = 1;
if( setsockopt(netPath->eventSock, SOL_SOCKET, SO_TIMESTAMP, &temp, sizeof(int)) < 0 ) {
PERROR(“failed to enable receive time stamps”);
return FALSE;
}
return TRUE;
}