ip.7p (2010 09)

i
IP(7P) IP(7P)
IP_MULTICAST_IF
(struct in_addr) Specifies a network interface other than the default
to be used when sending multicast datagrams through this socket.
Default: multicast datagrams are sent from the interface associated with
the specific multicast group, with the default multicast route or with the
default route.
IP_MULTICAST_LOOP
(unsigned char; boolean) Enables or disables loopback in the IP layer
for multicast datagrams sent through this socket. The value of the vari-
able pointed to by optval is zero (disable) or non-zero (enable). This
option is provided for compatibility only. Normally, multicast datagrams
are always looped back if the system has joined the group. See DEPEN-
DENCIES below. Default: enabled.
IP_MULTICAST_TTL
(unsigned char) Specifies the time-to-live value for multicast
datagrams sent through this socket. The value of the variable pointed to
by optval can be zero through 255. Default: one.
An application joins a multicast group on a network interface in order to receive multicast datagrams
sent on the network to which that interface connects. An application can join up to
IP_MAX_MEMBERSHIPS
multicast groups on each socket. IP_MAX_MEMBERSHIPS
is defined in
<netinet/in.h>
. However, each network interface may impose a smaller system-wide limit because
of interface resource limitations and because the system uses some link-layer multicast addresses.
The application must also bind to the destination port number in order to receive datagrams that are sent
to that port number. If the application binds to the address
INADDR_ANY, it may receive all datagrams
that are sent to the port number. If the application binds to a multicast group address, it may receive
only datagrams sent to that group and port number. It is not necessary to join a multicast group in order
to send datagrams to it.
For each multicast group that an application joins on a given socket and network interface, there is an
associated filter mode and source list. The filter mode can be "exclude" mode or "include" mode. The
source list is a set of IP addresses which will be compared to the source addresses of received multicast
datagrams.
An application uses "exclude" mode when it wants to block reception of multicast datagrams from a
specific set of sources, while allowing multicast datagrams from all other sources. For groups in "exclude"
mode, the source list may be empty, thus allowing reception of multicast datagrams from all sources.
An application uses "include" mode when it wants to allow reception of multicast datagrams from a
specific set of sources, while blocking multicast datagrams from all other sources. For groups in "include"
mode, the source list needs to contain at least one member in order for the application to stay joined to
the group; removing the last address from an "include" mode source list will cause the application to leave
the group.
IP_ADD_MEMBERSHIP
and MCAST_JOIN_GROUP request that the system join a multicast group on the
specified interface. The group is joined in "exclude" mode, with an empty source list. The
imr_interface field holds the IPv4 address of a local interface, or INADDR_ANY. The
gr_interface field holds the interface index of a local interface, or zero. If the interface address is
INADDR_ANY, or if the interface index is zero, the system joins the specified group on the interface from
which datagrams for that group would be sent, based on the routing configuration. For example:
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr("224.1.2.3");
mreq.imr_interface.s_addr = INADDR_ANY;
setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
struct group_req gr;
struct sockaddr_in *sin;
sin = (struct sockaddr_in *)&gr.gr_group;
bzero(sin, sizeof(*sin));
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = inet_addr("224.1.2.3");
gr.gr_interface = 0;
setsockopt(s, IPPROTO_IP, MCAST_JOIN_GROUP, &gr, sizeof(gr));
IP_DROP_MEMBERSHIP and MCAST_LEAVE_GROUP allow the system to leave a multicast group. The
imr_interface field holds the IPv4 address of a local interface, or INADDR_ANY. The
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010