Use the MCAST_JOIN_SOURCE_GROUP option to set the IPv4 or IPv6 multicast address, source address, and the local interface index. Use the SETSOCKOPT API and specify the address of the GROUP_SOURCE_REQ structure that contains these addresses and the interface index. The application can join multiple source multicast groups on a single socket and can also join the same group on multiple interfaces on the same socket. However, there is a maximum limit of 20 groups per single UDP socket and there is a maximum limit of 256 groups per single RAW socket. The stack chooses a default multicast interface if the interface index 0 is passed. The format of the GROUP_SOURCE_REQ structure is in the BPXYSOCK macro. The assembler program example in Figure 1 shows this socket option using the EZASMI macro:
***********************************************************************
* *
* Issue SETSOCKOPT - MCAST_JOIN_SOURCE_GROUP *
* *
***********************************************************************
EZASMI TYPE=SETSOCKOPT, ISSUE SETSOCKOPT X
S=S, SOCKET DESCRIPTOR X
OPTLEN=OPTL264, OPTION LENGTH X
OPTNAME='MCAST_JOIN_SOURCE_GROUP', OPTION NAME X
OPTVAL=GSR_REQ1, OPTION VALUE X
ERRNO=ERRNO, (SPECIFY ERRNO FIELD) X
RETCODE=RETCODE, (SPECIFY RETCODE FIELD) X
ERROR=ERROR ABEND IF MACRO ERROR
BAL R14,RCCHECK --> CHECK IT
*
* Here your program will perform normal processing such as sending or
* receiving message.
*
***********************************************************************
* *
* Issue SETSOCKOPT - MCAST_LEAVE_SOURCE_GROUP *
* *
***********************************************************************
EZASMI TYPE=SETSOCKOPT, ISSUE SETSOCKOPT X
S=S, SOCKET DESCRIPTOR X
OPTLEN=OPTL264, OPTION LENGTH X
OPTNAME='MCAST_LEAVE_SOURCE_GROUP', OPTION NAME X
OPTVAL=GSR_REQ1, OPTION VALUE X
ERRNO=ERRNO, (SPECIFY ERRNO FIELD) X
RETCODE=RETCODE, (SPECIFY RETCODE FIELD) X
ERROR=ERROR ABEND IF MACRO ERROR
BAL R14,RCCHECK --> CHECK IT
To remove the host from the source multicast host group you must issue a SETSOCKOPT call with the MCAST_LEAVE_SOURCE_GROUP option. This call is similar to the MCAST_JOIN_SOURCE_GROUP option because it also uses the GROUP_SOURCE_REQ structure to declare the IPv4 or IPv6 multicast address, source address, and the local interface index (see Figure 1). You can also use the MCAST_LEAVE_GROUP option to remove all sources for a given multicast group.
While the application is a member of the source multicast host group, datagrams can be sent or received as required. To see the multicast groups that are joined on an interface, use the Netstat DEvlinks/-d command. To see the multicast groups that are joined on a socket, use the Netstat ALL/-A command.