ip.7p (2010 09)

i
IP(7P) IP(7P)
struct group_source_req gsr;
struct sockaddr_in *sin;
sin = (struct sockaddr_in *)&gsr.gsr_group;
bzero(sin, sizeof(*sin));
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = inet_addr("224.1.2.3");
sin = (struct sockaddr_in *)&gsr.gsr_source;
bzero(sin, sizeof(*sin));
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = inet_addr("10.4.5.6");
gsr.gsr_interface = 0;
setsockopt(s, IPPROTO_IP, MCAST_JOIN_SOURCE_GROUP, &gsr, sizeof(gsr));
setsockopt(s, IPPROTO_IP, MCAST_LEAVE_SOURCE_GROUP, &gsr, sizeof(gsr));
IP_MULTICAST_IF
specifies a local network interface to be used when sending multicast datagrams
through this socket. For example:
#include <arpa/inet.h>
struct in_addr addr;
addr.s_addr = inet_addr("192.1.2.3");
setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr));
Normally, applications do not need to specify the interface. By default, multicast datagrams are sent
from the interface specified by the routing configuration, namely the interface associated with the specific
multicast group, with the default multicast route or with the default route. If addr is set to the address
INADDR_ANY, the default interface is selected. Otherwise, addr should be the IP address of a local
interface.
IP_MULTICAST_LOOP
enables or disables loopback for multicast datagrams sent through this socket.
For example:
unsigned char loop = 1;
setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));
Note that the type of the optval parameter is unsigned char instead of int, which is common for
boolean socket options. This option is provided for compatibility only. Normally, if a multicast datagram
is sent to a group that the system has joined, a copy of the datagram is always looped back and delivered
to any applications that are bound to the destination port. See DEPENDENCIES below.
IP_MULTICAST_TTL
controls the scope a multicast by setting the time-to-live value for multicast
datagrams sent through this socket. For example:
unsigned char ttl = 64;
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
Note that the type of optval parameter is unsigned char instead int, which is common for socket
options. By default, the time-to-live field (TTL) is one, which limits the multicast to the local network. If
the TTL is zero, the multicast is limited to the local system (loopback). If the TTL is two, the multicast
can be forwarded through at most one gateway; and so forth. Multicast datagrams can be forwarded to
other networks only if there are special multicast routers on the local and intermediate networks.
DEPENDENCIES
The behavior of
IP_MULTICAST_LOOP depends on the network driver and interface card. Normally,
loopback cannot be disabled, even if IP_MULTICAST_LOOP is set to zero, because it occurs in the driver
or in the network interface. However, if the outbound interface is lo0 (127.0.0.1), or if
IP_MULTICAST_TTL is set to zero, setting IP_MULTICAST_LOOP
to zero will disable loopback for
multicast datagrams sent through the socket.
ERRORS
One of the following errors may be returned if a call to
setsockopt() or getsockopt() fails.
[EADDRINUSE] The specified multicast group has been joined already on socket.
[EADDRNOTAVAIL] The specified IP address is not a local interface address; or there is no
route for the specified multicast address; or the specified multicast group
has not been joined.
4 Hewlett-Packard Company 4 HP-UX 11i Version 3: September 2010