SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
IPv4 and IPv6 multicasts allow for one-to-many communication over an IP network. If a device is interested in receiving multicasts which are sent to a specific group of devices, it may join or leave the group by sending join or leave messages. The UDP socket that joined a group receives group multicast packets in addition to the regular unicast packets. Television is a good example of multicasting, where each channel is transmitted on a different multicast group. When a user changes the channel, the UDP socket leaves the multicast group and joins another multicast group.
The SimpleLink device supports IPv4 IGMPv2 and IPv6 MLDv1 protocols for joining and leaving groups. Users can support up to eight IPv4 multicast groups and up to eight IPv6 multicast groups. Two UDP sockets which join the same group decrease the available multicast groups only by one.
To join or leave a group, use sl_SetSockOpt with the options listed in Table 7-3.
SL_IP_ADD_MEMBERSHIP | Join IPv4 group |
SL_IP_DROP_MEMBERSHIP | Leave IPv4 group |
SL_IPV6_ADD_MEMBERSHIP | Join IPv6 group |
SL_IPV6_DROP_MEMBERSHIP | Leave IPv6 group |
An example of joining the IPv4 multicast group:
_i16 Status;
SlSockIpMreq_t MulticastIp;
MulticastIp.imr_multiaddr.s_addr = sl_Htonl(SL_IPV4_VAL(224,0,1,200));
MulticastIp.imr_interface.s_addr = SL_INADDR_ANY;
Status = sl_SetSockOpt(Sd, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP,(char*) &MulticastIp, sizeof(MulticastIp));
if( Status )
{
// error
}
An example of leaving the IPv4 multicast group:
_i16 Status;
SlSockIpMreq_t MulticastIp;
MulticastIp.imr_multiaddr.s_addr = sl_Htonl(SL_IPV4_VAL(224,0,1,200));
MulticastIp.imr_interface.s_addr = SL_INADDR_ANY;
Status = sl_SetSockOpt(Sd, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP,(char*) &MulticastIp, sizeof(MulticastIp));
if( Status )
{
// error
}