Skip to content

Commit efca479

Browse files
authored
Merge 35bcb34 into e6810a4
2 parents e6810a4 + 35bcb34 commit efca479

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

modules/ca/src/client/repeater.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "caProto.h"
7575
#include "udpiiu.h"
7676
#include "repeaterClient.h"
77+
#include "addrList.h"
7778

7879

7980
/*
@@ -92,7 +93,7 @@ static int makeSocket ( unsigned short port, bool reuseAddr, SOCKET * pSock )
9293
SOCKET sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, 0 );
9394

9495
if ( sock == INVALID_SOCKET ) {
95-
*pSock = sock;
96+
*pSock = sock;
9697
return SOCKERRNO;
9798
}
9899

@@ -517,6 +518,60 @@ void ca_repeater ()
517518
return;
518519
}
519520

521+
#ifdef IP_ADD_MEMBERSHIP
522+
/*
523+
* join UDP socket to any multicast groups
524+
*/
525+
{
526+
ELLLIST casBeaconAddrList = ELLLIST_INIT;
527+
ELLLIST dummy = ELLLIST_INIT;
528+
529+
/*
530+
* collect user specified beacon address list;
531+
* check BEACON_ADDR_LIST list first; if no result, take CA_ADDR_LIST
532+
*/
533+
if(!addAddrToChannelAccessAddressList(&casBeaconAddrList,&EPICS_CAS_BEACON_ADDR_LIST,port,0)) {
534+
addAddrToChannelAccessAddressList(&casBeaconAddrList,&EPICS_CA_ADDR_LIST,port,0);
535+
}
536+
537+
/* First clean up */
538+
removeDuplicateAddresses(&casBeaconAddrList, &dummy , 0);
539+
540+
osiSockAddrNode *pNode;
541+
for(pNode = (osiSockAddrNode*)ellFirst(&casBeaconAddrList);
542+
pNode;
543+
pNode = (osiSockAddrNode*)ellNext(&pNode->node))
544+
{
545+
546+
if(pNode->addr.ia.sin_family==AF_INET) {
547+
epicsUInt32 top = ntohl(pNode->addr.ia.sin_addr.s_addr)>>24;
548+
if(top>=224 && top<=239) {
549+
550+
/* This is a multi-cast address */
551+
struct ip_mreq mreq;
552+
553+
memset(&mreq, 0, sizeof(mreq));
554+
mreq.imr_multiaddr = pNode->addr.ia.sin_addr;
555+
mreq.imr_interface.s_addr = INADDR_ANY;
556+
557+
if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
558+
(char *) &mreq, sizeof(mreq)) != 0) {
559+
struct sockaddr_in temp;
560+
char name[40];
561+
char sockErrBuf[64];
562+
temp.sin_family = AF_INET;
563+
temp.sin_addr = mreq.imr_multiaddr;
564+
temp.sin_port = htons ( port );
565+
epicsSocketConvertErrnoToString (sockErrBuf, sizeof ( sockErrBuf ) );
566+
ipAddrToDottedIP (&temp, name, sizeof(name));
567+
errlogPrintf("caR: Socket mcast join to %s failed: %s\n", name, sockErrBuf );
568+
}
569+
}
570+
}
571+
}
572+
}
573+
#endif
574+
520575
debugPrintf ( ( "CA Repeater: Attached and initialized\n" ) );
521576

522577
while ( true ) {

0 commit comments

Comments
 (0)