setsockopt

Name

setsockopt -- set options on sockets

Synopsis

#include <sys/socket.h>
#include <netinet/in.h>

int setsockopt(int sockfd, int level, int optname, void *optval, socklen_t optlen);

Description

In addition to the setsockopt options specified in SUSv3, setsockopt also supports the options specified here.

The following setsockopt operations are provided for level IPPROTO_IP:

IP_MULTICAST_TTL

Set or reads the time-to-live value of outgoing multicast packets for this socket. optval is a pointer to an integer which contains the new TTL value.

IP_MULTICAST_LOOP

Sets a boolean flag indicating whether multicast packets originating locally should be looped back to the local sockets. optval is a pointer to an integer which contains the new flag value.

IP_ADD_MEMBERSHIP

Join a multicast group. optval is a pointer to a ip_mreq structure. Before calling, the caller should fill in the imr_multiaddr field with the multicast group address and the imr_address field with the address of the local interface. If imr_address is set to INADDR_ANY, then an appropriate interface is chosen by the system.

IP_DROP_MEMBERSHIP

Leave a multicast group. optval is a pointer to a ip_mreq structure containing the same values as were used with IP_ADD_MEMBERSHIP.

IP_MULTICAST_IF

Set the local device for a multicast socket. optval is a pointer to a ip_mreq structure initialized in the same manner as with IP_ADD_MEMBERSHIP.

The ip_mreq structure contains two struct in_addr fields: imr_multiaddr and imr_address.

Return Value

On success, 0 is returned. On error, -1 is returned and the global variable errno is set appropriately.