IP Multicasts
The use of IP multicasting enables a message to be transmitted to a group of hosts, instead of having to address and send the message to each group member individually. Internet addressing provides for Class D addressing that is used for multicasting.
struct ip_mreq{
struct in_addr imr.imr_interface.s_addr;
struct in_addr imr.imr_multiaddr.s_addr;
}
struct in_addr{
ulong s_addr;
}
In order to send to a multicasting group it is not necessary to join the groups. For receiving transmissions sent to a multicasting group, membership is required. For multicast sending, use an IP_MULTICAST_IF flag with the setsockopt subroutine. This specifies the interface to be used. It may be necessary to call the setsockopt subroutine with the IP_MULTICAST_LOOP flag in order to control the loopback of multicast packets. By default, packets are delivered to all members of the multicast group including the sender, if it is a member. However, this can be disabled with the setsockopt subroutine using the IP_MULTICAST_LOOP flag.
| Item | Description |
|---|---|
| IP_ADD_MEMBERSHIP | Joins a multicast group as specified in the OptionValue parameter of type struct ip_mreq. |
| IP_DROP_MEMBERSHIP | Leaves a multicast group as specified in the OptionValue parameter of type struct ip_mreq. |
| IP_MULTICAST_IF | Permits sending of multicast messages on an interface as specified in the OptionValue parameter of type struct ip_addr. An address of INADDR_ANY (0x000000000) removes the previous selection of an interface in the multicast options. If no interface is specified then the interface leading to the default route is used. |
| IP_MULTICAST_LOOP | Sets multicast loopback, determining whether or not transmitted messages are delivered to the sending host. An OptionValue parameter of type char is used to control loopback being on or off. |
| IP_MULTICAST_TTL | Sets the time-to-live (TTL) for multicast packets. An OptionValue parameter of type char is used to set this value between 0 and 255. |
Beginning with AIX® 6.1, Internet Group Management Protocol (IGMPv3) is supported. IGMPv3 allows hosts to filter source addresses. You can block packet transmissions from specific source addresses to specific multicast groups, or allow packet transmissions from specific source addresses to specific multicast groups by using the setsockopt subroutine with the following flags:
| Item | Description |
|---|---|
| IP_BLOCK_SOURCE | Blocks data from a given source address to a given group. Use the ip_mreq_source structure with this flag. |
| IP_UNBLOCK_SOURCE | Unblocks a blocked source. Use the ip_mreq_source structure with this flag. |
| IP_ADD_SOURCE_MEMBERSHIP | Joins a multicast group that has a specific source address. If already not a member of the group, this subroutine joins the multicast group and accepts data from the given source address. If already a member of the multicast group, this subroutine also accepts data from this source address. Use the ip_mreq_source structure with this flag. |
| IP_DROP_SOURCE_MEMBERSHIP | Leaves a multicast group that has a specific source address. This subroutine drops the source address from a given multicast group list. Use the IP_DROP_MEMBERSHIP subroutine to drop all source addresses of a group. Use the ip_mreq_source structure with this flag. |
struct ip_mreq_source {
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_sourceaddr; /* IP address of source */
struct in_addr imr_interface; /* local IP address of interface */
}
The following examples demonstrate the use of the setsockopt function with the protocol level set to Internet Protocol (IPPROTO_IP).
To mark a socket for sending to a multicast group on a particular interface:
struct ip_mreq imr;
setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &imr.imr_interface.s_addr, sizeof(struct in_addr));
char loop = 0;
setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(char));
int on = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(int));
struct ip_mreq imr;
setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(struct ip_mreq));
struct ip_mreq imr;
setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &imr, sizeof(struct ip_mreq));
The getsockopt function can also be used with the multicast flags to obtain information about a particular socket.
| Item | Description |
|---|---|
| IP_MULTICAST_IF | Retrieves the interface's IP address. |
| IP_MULTICAST_LOOP | Retrieves the specified looping mode from the multicast options. |
| IP_MULTICAST_TTL | Retrieves the time-to-live in the multicast options. |