#include <sys/types.h> #include <sys/socket.h> int setsockopt(int socket_descriptor, int level, int option_name, char *option_value, int option_length)
#define _XOPEN_SOURCE 520 #include <sys/socket.h> int setsockopt(int socket_descriptor, int level, int option_name, const void *option_value, socklen_t option_length)
The setsockopt() function is used to set socket options.
There are two versions of the API, as shown above. The base IBM i® API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.
IPPROTO_IP | Request applies to IP protocol layer. |
IPPROTO_TCP | Request applies to TCP protocol layer. |
SOL_SOCKET | Request applies to socket layer. |
IPPROTO_IPV6 | Request applies to IPv6 protocol layer. |
IPPROTO_ICMPV6 | Request applies to ICMPv6 protocol layer. |
Note: Options directed to a specific protocol level are only supported by that protocol. An option that is directed to the SOL_SOCKET level always completes successfully. This provides compatibility with Berkeley Software Distributions implementations that also shield the application from protocols that do not support an option.
Socket Options That Apply to the IP Layer (IPPROTO_IP)
Option | Description and Option Value |
---|---|
IP_ADD_MEMBERSHIP | Join a multicast group. A maximum of
IP_MAX_MEMBERSHIPS groups may be joined per socket. This option is only
supported for sockets with an address family of AF_INET and type
of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type struct ip_mreq is used to set this value. This structure is defined in <netinet/in.h> as: struct ip_mreq { struct in_addr imr_multiaddr; /* IP multicast address of group */ struct in_addr imr_interface; /* local IP address of interface */ };The imr_multiaddr field is used to specify the multicast group to join or leave. The imr_interface field is used to specify the local IP address that is associated with the interface to which this request applies. If INADDR_ANY is specified for the local interface, the default multicast interface will be selected. Note: Reception of IP multicast datagrams may require configuration changes to the line description to enable the adapter to receive packets with a multicast destination address. On Ethernet, for example, the Ethernet group address that is associated with the IP group address must be specified by the GRPADR parameter on the line description. To determine the Ethernet group address for a particular IP group address, the low-order 23 bits of the IP address are placed into the low-order 23 bits of the Ethernet group address 01.00.5E.xx.xx.xx. |
IP_ADD_SOURCE_MEMBERSHIP | Join a source-specific multicast group. A maximum
of IP_MAX_MEMBERSHIPS groups may be joined per socket. This option is only
supported for sockets with an address family of AF_INET and type
of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type struct ip_mreq_source is used to set this value. This structures is defined in <netinet/in.h> as: struct ip_mreq_source { struct in_addr imr_multiaddr; /* IP address of group */ struct in_addr imr_sourceaddr; /* IP address of source */ struct in_addr imr_interface; /* IP address of interface */ };The imr_multiaddr field specifies the multicast group address. The imr_sourceaddr field specifies the source address. The imr_interface field specifies the address of the interface. |
IP_BLOCK_SOURCE | Block data from a given source to a given
multicast group. This option is supported for sockets with an address
family of AF_INET and type of SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct ip_mreq_source is used to set this value. See IP_ADD_SOURCE_MEMBERSHIP for more information about the ip_mreq_ip_mreq_source structure. |
IP_DONTFRAG | Set or reset the don't fragment flag in the IP
header. This option is supported for sockets with an address family of
AF_INET and type of SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning the kernel will discard the packet instead of inserting the fragment header. |
IP_DROP_MEMBERSHIP | Leave a multicast group. This option is only
supported for sockets with an address family of AF_INET and type
of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type struct ip_mreq is used to set this value. See IP_ADD_MEMBERSHIP for more information about the ip_mreq structure. |
IP_DROP_SOURCE_MEMBERSHIP | Leave a source-specific multicast group.
This option is only
supported for sockets with an address family of AF_INET and type
of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type struct ip_mreq_source is used to set this value. See IP_ADD_SOURCE_MEMBERSHIP for more information about the ip_mreq_ip_mreq_source structure. |
IP_MULTICAST_IF | Set interface over which outgoing multicast
datagrams should be sent. This option is only supported for sockets with
an address family of AF_INET and type of SOCK_DGRAM
or SOCK_RAW. An option_value parameter of type in_addr is used to set this value. This structure is defined in <netinet/in.h> as: struct in_addr { u_long s_addr; /* IP address */ };The s_addr field specifies the local IP address that is associated with the interface over which outgoing multicast datagrams should be sent. An address of INADDR_ANY removes the previous selection. |
IP_MULTICAST_LOOP | Specify that a copy of an outgoing multicast
datagram should be delivered to the sending host as long as it is a member of
the multicast group. This option is only supported
for sockets with an address family of AF_INET and type of
SOCK_DGRAM or SOCK_RAW. An option_value parameter of type char is used to set this value. A non-zero value (default), indicates that multicast datagrams sent by this system should also be delivered to this system as long as it is a member of the multicast group. A value of 0x00 disables the option meaning a copy of the datagram will not be delivered to the sending host. |
IP_MULTICAST_TTL | Set Time To Live (TTL) in the IP header for
outgoing multicast datagrams. This option is only supported for
sockets with an address family of AF_INET and type of
SOCK_DGRAM or SOCK_RAW. An option_value parameter of type char is used to set this value between 0 and 255. |
IP_OPTIONS | Set IP header options. This is only supported for
sockets with an address family of AF_INET. An option_value parameter of type char[] representing the IP options as specified in RFC 791. The character string varies depending on which options are selected. Each option is made up of a single byte representing the option code, and may be followed by a length field (1 byte) and data for the option. The IP options that can be set are:
Notes:
|
IP_RECVLCLIFADDR | Indicates if the local interface that a datagram
to be received should be returned. This option is only supported for sockets
with an address family of AF_INET and type of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option indicating the first 4 bytes of the reserved field of the sockaddr structure will contain the local interface. |
IP_RECVPKTINFO | Determine if the destination address and interface
of incoming packets will be returned as ancillary data on recvmsg().
This option is supported for sockets with an address family of
AF_INET and type of SOCK_DGRAM or
SOCK_RAW only. This option is not
supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IP_PKTINFO will be received on recvmsg(). |
IP_TOS | Set Type Of Service (TOS) and Precedence in the
IP header. This option is only supported for sockets with an address family of
AF_INET. An option_value parameter of type int is used to set this value. Note: Only the rightmost octet (least significant octet) of the integer value is used. |
IP_TTL | Set Time To Live (TTL) in the IP header. This
option is only supported for sockets with an address family
AF_INET. An option_value parameter of type int is used to set this value. Note:Only the rightmost octet (least significant octet) of the integer value is used. |
IP_UNBLOCK_SOURCE | Unblock data from a given source to a given group.
This option is supported for sockets with an address family of
AF_INET and type of SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct ip_mreq_source is used to set this value. See IP_ADD_SOURCE_MEMBERSHIP for more information about the ip_mreq_ip_mreq_source structure. |
MCAST_BLOCK_SOURCE | Block data from a given source to a given group.
To unblock the data use the MCAST_UNBLOCK_SOURCE option. This option is
supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. This structures is defined in <netinet/in.h> as: struct group_source_req { uint32_t gsr_interface; /* interface index */ struct sockaddr_storage gsr_group; /* group address */ struct sockaddr_storage gsr_source; /* source address */ };The gsr_interface field specifies the address of the interface. The gsr_group field specifies the group address. The gsr_source field specifies the source address. |
MCAST_JOIN_GROUP | Join an any-source group.
To leave the any-source group use the MCAST_LEAVE_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_req is used to set this value. The structure is defined in <netinet/in.h> as: struct group_req { uint32_t gr_interface; /* interface addr */ struct sockaddr_storage gr_group; /* group address */ };The gr_interface field specifies the address of the interface. The gr_group field specifies the group address. |
MCAST_JOIN_SOURCE_GROUP | Join a source-specific group.
To leave the source-specific group use the MCAST_LEAVE_SOURCE_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. See MCAST_BLOCK_SOURCE for more information about the group_source_req structure. |
MCAST_LEAVE_GROUP | Leave an any-source group.
To join the any-source group use the MCAST_JOIN_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_req is used to set this value. See MCAST_JOIN_GROUP for more information about the group_req structure. |
MCAST_LEAVE_SOURCE_GROUP | Leave a source-specific group.
To join a source-specific group use the MCAST_JOIN_SOURCE_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. See MCAST_BLOCK_SOURCE for more information about the group_source_req structure. |
MCAST_UNBLOCK_SOURCE | Unblocks data from a given source to a given group.
To block the data use the MCAST_BLOCK_SOURCE
option. This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. See MCAST_BLOCK_SOURCE for more information about the group_source_req structure. |
Socket Options That Apply to the TCP Layer (IPPROTO_TCP)
Option | Description and Option Value |
---|---|
TCP_KEEPALIVE | Specifies the socket-specific keep alive timeout, in seconds, that TCP waits
before sending out a probe to the other side of the connection. This setting is
socket specific and will be used in place of the TCP attribute
TCPKEEPALV. It is only used if SO_KEEPALIVE is enabled on
the socket. This option is only supported for sockets with an address family of
AF_INET or AF_INET6 and type of
SOCK_STREAM. An option_value parameter of type unsigned int is used to set the keep alive timeout, in seconds. A value of 0 (default), indicates that the value set for TCPKEEPALV on the CHGTCPA command will be used. A nonzero value indicates the time in seconds TCP will wait before sending out a probe to the other side of the connection. Changes to this option have no effect after the socket has connected. |
TCP_NODELAY | Specifies whether TCP should follow the Nagle
algorithm for deciding when to send data.
This option is only supported for sockets with an address family of
AF_INET or AF_INET6 and type
of SOCK_STREAM. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option meaning TCP will follow the Nagle algorithm. A non-zero value sets the option forcing TCP to always send data immediately. For example, TCP_NODELAY should be used when there is an application using TCP for a request/response. |
Socket Options That Apply to the Socket Layer (SOL_SOCKET )
Option | Description and Option Value |
---|---|
SO_ACCEPTECONNABORTED | Enable the listening socket such that a blocking accept() will return
ECONNABORTED when a connection on the listening backlog is reset prior to the
accept(). This option is only used by sockets with an address family of
AF_INET or AF_INET6. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning a blocking accept() will return ECONNABORTED when a connection on the listening backlog is reset prior to the accept(). A backlog entry is created when a new connection is established to the listener socket. The accept() call will consume all leading invalid entries in the backlog, until a valid entry is located or the backlog is exhausted. If the backlog contains no entries or a valid entry is located, the option has no effect. If the backlog contains at least one invalid entry and there are no valid entries, the accept() will return -1 with errno set to ECONNABORTED. The option is only valid on a socket that has successfully issued the listen() call. The option has no effect on non-blocking sockets. |
SO_ACCEPTEPERM | Enable the listening socket such that any sockets API that accepts connections
will return EPERM when a connection on the listening socket is rejected by a
user exit program registered for QIBM_QSO_ACCEPT.
The option is only valid on a socket that has successfully issued
the listen() call. This option is only used by sockets with an address
family of AF_INET or AF_INET6. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option meaning incoming connections that are rejected by a user exit program will be silently ignored and the sockets API that issued the accept will continue to wait for the next incoming connection. A non-zero value sets the option meaning rejected incoming connections will result in the sockets API that tried to accept the connection to return -1 with errno set to EPERM. |
SO_BROADCAST | Enable the socket for issuing messages to a
broadcast address. This option is only supported for sockets with an address
family of AF_INET and type SOCK_DGRAM or
SOCK_RAW. The broadcast address to be used may be determined by
issuing an ioctl() with the SIOCGIFBRDADDR
request. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option enabling the socket for issuing messages to a broadcast address. |
SO_DEBUG | Indicates if low level-debugging is
active. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option activating low level-debugging. |
SO_DONTROUTE | Bypass normal routing mechanisms. This option is
only supported by sockets with an address family of AF_INET or
AF_INET6. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option indicating to bypass normal routing mechanisms. |
SO_KEEPALIVE | Keep the connection up by sending periodic
transmissions. This option is only supported for sockets of an address family
of AF_INET or AF_INET6 and type
SOCK_STREAM. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning TCP should keep the connection up by sending periodic transmissions. |
SO_LINGER | Indicates if the system attempts delivery of any
buffered data or if the system discards it when a close() is issued.
This option is for sockets that are using a connection-oriented transport
service with an address family of AF_INET or
AF_INET6. An option_value parameter of type struct linger is used to set this value. This structure is defined in <sys/socket.h> as: struct linger { int l_onoff; int l_linger; };The l_onoff field determines if the linger option is set. A nonzero value indicates the linger option is set and is using the l_linger value. A zero value (default) indicates that the option is not set. The l_linger field is the time to wait before any buffered data to be sent is discarded. The following occur on a close():
|
SO_OOBINLINE | Indicates whether out-of-band data is received
inline with normal data. This option is only supported for sockets with an
address family of AF_INET or AF_INET6. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning out-of-band data is received inline with normal data. |
SO_RCVBUF | Set the size of the receive buffer. An option_value parameter of type int is used to set this value. |
SO_RCVLOWAT | Set the size of the receive low-water mark. This
option is only supported for sockets with a type of SOCK_STREAM. An option_value parameter of type int is used to set this value. The default size is 1. |
SO_RCVTIMEO | Set the receive timeout value. This option is not
supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type timeval is used to set this value. This structure is defined in <sys/time.h> as: struct timeval { long tv_sec; long tv_usec; };The tv_sec field is the number of seconds. The tv_usec field is the number of microseconds. |
SO_REUSEADDR | Indicates if the local socket address can be
reused. This option is supported by sockets with an address family of
AF_INET or
AF_INET6 and a
type of SOCK_STREAM or SOCK_DGRAM. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option indicating the local socket address can be reused. |
SO_SNDBUF | Set the size of the send buffer. An option_value parameter of type int is used to set this value. |
SO_SNDLOWAT | Set the size of the send low-water mark. This option is not supported. |
SO_SNDTIMEO | Set the send timeout value. This option is not
supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type timeval is used to set this value. This structure is defined in <sys/time.h> as: struct timeval { long tv_sec; long tv_usec; };The tv_sec field is the number of seconds. The tv_usec field is the number of microseconds. |
SO_USELOOPBACK | Indicates if the loopback feature is being used. This option is not supported. |
Socket Options That Apply to the IPv6 Layer (IPPROTO_IPV6)
Option | Description and Option Value |
---|---|
IPV6_ADDR_PREFERENCES | Set the current settings for source address
selection. This setting is socket specific. This option is supported for sockets
with an address family of AF_INET6 only. An option_value parameter of type int is used to set this value. A value of 0 (default) means the option is disabled and default source address selection rules will be used. A non-zero value indicates a flag combination of preferences meaning these flags preferences will be used for source address selection on connect(), sendmsg(), and sendto(). The valid source address selection preference flags are defined in <in.h> as: #define IPV6_PREFER_SRC_HOME 0x00000001 /* Prefer Home addr */ #define IPV6_PREFER_SRC_COA 0x00000002 /* Prefer Care-of addr */ #define IPV6_PREFER_SRC_TMP 0x00000004 /* Prefer Temp addr */ #define IPV6_PREFER_SRC_PUBLIC 0x00000008 /* Prefer Public addr */ #define IPV6_PREFER_SRC_CGA 0x00000010 /* Prefer CGA addr */ #define IPV6_PREFER_SRC_NONCGA 0x00000020 /* Prefer non-CGA addr */ |
IPV6_CHECKSUM | Set if the kernel will calculate and insert a
checksum for output and verify the received checksum on input, discarding the
packet if the checksum is in error for this socket. This option
is only supported for sockets with an address family of AF_INET6
and type of SOCK_RAW with a protocol other than
IPPROTO_ICMPV6. The checksum is automatically computed for
protocol IPPROTO_ICMPV6. An option_value parameter of type int is used to set this value. If this option is -1 (the default), this socket option is disabled. A value of 0 or greater specifies an integer offset into the user data of where the checksum is located. This must be an even integer value. |
IPV6_DONTFRAG | Set if the kernel will not implement the
automatic insertion of a fragment header in the packet if the packet is too big
for the path MTU. This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning the kernel will discard the packet instead of inserting the fragment header. |
IPV6_DSTOPTS | Set the sticky destination options following the
routing header or without a routing header.
This option is supported for sockets with an address family of
AF_INET6 only. An option_value parameter of type struct ip6_dest is used to set this value. This structure is defined in <netinet/ip6.h> as: struct ip6_dest { uint8_t ip6d_nxt; /* next header */ uint8_t ip6d_len; /* length in units of 8 octets */ /* followed by options */ };The ip6d_nxt field specifies the option type of the next header in the chain of headers. The ip6d_len field specifies the length of the destination header in units of 8 octets, not including the first 8 octets. To clear the destination options header, pass a value of 0 for option_length. |
IPV6_HOPOPTS | Set the sticky hop-by-hop options header.
This option is supported for sockets with an address family of
AF_INET6 only. An option_value parameter of type struct ip6_hbh is used to set this value. The structure is defined in <netinet/ip6.h> as: struct ip6_hbh { uint8_t ip6h_nxt; /* next header */ uint8_t ip6h_len; /* length in units of 8 octets */ /* followed by options */ };The ip6h_nxt field specifies the offset of the next header in the chain of headers. The ip6h_len field specifies the length of the hop-by-hop header in units of 8 octets, not including the first 8 octets. To clear the hop-by-hop options header, pass a value of 0 for option_length. |
IPV6_JOIN_GROUP | Join a multicast group. A maximum of
IP_MAX_MEMBERSHIPS groups may be joined per socket.
This option is only supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type struct ipv6_mreq is used to set this value. This structure is defined in <netinet/in.h> as: struct ipv6_mreq { struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address */ unsigned int ipv6mr_interface; /* interface index */ };The ipv6mr_multiaddr field is used to specify the multicast group to join or leave. The ipv6mr_interface field is used to specify the interface to which this request applies. If 0 is specified for the interface, the system will choose the local interface. |
IPV6_LEAVE_GROUP | Leave a multicast group.
This option is only supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type struct ipv6_mreq is used to set this value. See IPV6_JOIN_GROUP for more information about the ipv6_mreq structure. |
IPV6_MULTICAST_HOPS | Set the hop limit value that will be used for
subsequent multicast packets sent by this socket.
This option is only supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type int is used to set this value between 0 and 255. The default value is 1. |
IPV6_MULTICAST_IF | Set the interface over which outgoing multicast
datagrams will be sent. This option is only supported for sockets with an
address family of AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW. An option_value parameter of type unsigned int is used to set the interface index that is associated with the interface over which outgoing multicast datagrams will be sent. |
IPV6_MULTICAST_LOOP | Set the multicast looping mode. This option is
only supported for sockets with an address family of AF_INET6 and
type of SOCK_DGRAM or SOCK_RAW. An option_value parameter of type unsigned int is used to set this value. A non-zero value (default), indicates that multicast datagrams sent by this system should also be delivered to this system as long as it is a member of the multicast group. If this option is 0, a copy of the datagram will not be delivered to the sending host. |
IPV6_NEXTHOP | Set the next hop address for outgoing packets.
This option is supported for sockets with an address family of
AF_INET6 only. An option_value parameter of type struct sockaddr_in6 is used to set this value. This structure is defined in <netinet/in.h> as: The BSD 4.4/UNIX 98 compatible structure is: struct sockaddr_in6 { uint8_t sin6_len; /* address length */ sa_family_t sin6_family; /* address family (AF_INET6) */ in_port_t sin6_port; /* transport layer port number */ uint32_t sin6_flowinfo; /* IPv6 flow information */ struct in6_addr sin6_addr; /* IPv6 address */ uint32_t sin6_scope_id; /* scope id for the interface */ };The sin6_len field specifies the length of the address specified in sin6_addr. The sin6_family field specifies the address family, AF_INET6. The sin6_port field specifies the port number. The sin6_flowinfo field specifies the IPv6 flow information. The sin6_addr field specifies the IPv6 address itself. The sin6_scope_id field specifies the IPv6 interface scope id. To clear the next hop address, pass a value of 0 for option_length. Notes:
|
IPV6_PKTINFO | Set source IPv6 address and the outgoing interface
index that an outgoing packet will use. This option is supported for sockets
with an address family of AF_INET6 only. An option_value parameter of type struct in6_pktinfo is used to set this value. The structure is defined in <netinet/in.h> as: struct in6_pktinfo { struct in6_addr ipi6_addr; /* Src/dst IPv6 address */ unsigned int ipi6_ifindex; /* Send/recv interface index */ };The ipi6_addr field specifies the source IPv6 address. The ipi6_ifindex field specifies the sending interface index. To clear the source address, pass a value of in6addr_any for ipi6_addr. To clear the outgoing interface index, pass a value of zero for ipi6_index. |
IPV6_PREFER_TEMPADDR | Set source address selection.
This option is supported for sockets with an address
family of AF_INET6 only. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning temporary addresses will be preferred as the source address. |
IPV6_RECVDSTOPTS | Determine if the destination options header
of incoming packets will be returned as ancillary data on recvmsg().
This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_DSTOPTS will be received on recvmsg(). |
IPV6_RECVHOPLIMIT | Determine if the hop limit of incoming
packets will be returned as ancillary data on recvmsg().
This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_HOPLIMIT will be received on recvmsg(). |
IPV6_RECVHOPOPTS | Determine if the hop-by-hop options header
of incoming packets will be returned as ancillary data on recvmsg().
This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_HOPOPTS will be received on recvmsg(). |
IPV6_RECVPATHMTU | Determine if the IPV6_PATHMTU items of incoming
packets will be returned as ancillary data on recvmsg(). This means when a data
packet that is too big is sent, the return code on recvmsg() will be 0,
indicating no data was received; however,
there will be ancillary data of cmsg_type IPV6_PATHMTU
as notification that the packet was too big.
This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_PATHMTU will be received on recvmsg(). NOTE: The next recvmsg() done after a sendmsg() that failed with EMSGSIZE, will not necessarily get the IPV6_PATHMTU ancillary data indicating the packet was too big. If there is previously sent data that has not yet been received, this data will be received prior to getting the IPV6_PATHMTU ancillary data on a separate recvmsg(). |
IPV6_RECVPKTINFO | Determine if the destination address and
interface index of incoming packets will be returned as ancillary data
on recvmsg(). This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_PKTINFO will be received on recvmsg(). |
IPV6_RECVRTHDR | Determine if the routing header
of incoming packets will be returned as ancillary data on recvmsg().
This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_RTHDR will be received on recvmsg(). |
IPV6_RECVTCLASS | Determine if the traffic class of incoming
packets will be returned as ancillary data on recvmsg().
This option is supported for sockets with an address family of
AF_INET6 and type of SOCK_DGRAM or
SOCK_RAW only. This option is
not supported unless _XOPEN_SOURCE is defined to be 520 or greater. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning ancillary data for IPV6_TCLASS will be received on recvmsg(). |
IPV6_RTHDR | Set the sticky routing header options.
This option is supported for sockets with an address family of
AF_INET6 only. An option_value parameter of type struct ip6_rthdr is used to set this value. This structure is defined in <netinet/ip6.h> as: struct ip6_rthdr { uint8_t ip6r_nxt; /* next header */ uint8_t ip6r_len; /* length in units of 8 octets */ uint8_t ip6r_type; /* routing type */ uint8_t ip6r_segleft; /* segments left */ /* followed by routing type specific data */ };The ip6r_nxt field specifies the routing header type of the next header in the chain of headers. The ip6r_len field specifies the length of the routing header in units of 8 octets, not including the first 8 octets. The ip6r_type field specifies the routing type. The ip6r_segleft field that is returned will be the number of hops remaining to reach the destination. The routing options can not be set after the socket has connected. To clear the routing header, pass a value of 0 for option_length. |
IPV6_RTHDRDSTOPTS | Set the sticky destination
options preceding the routing header. All current destination
options can be put after the routing header or used without a routing header, so IPV6_DSTOPTS can be used and
IPV6_RTHDRDSTOPTS should be avoided whenever possible.
This option is supported for sockets with an address family of
AF_INET6 only. An option_value parameter of type struct ip6_dest is used to set this value. See IPV6_DSTOPTS for more information about the ip6_dest structure. Use of IPV6_DSTOPTS should be used in place of IPV6_RTHDRDSTOPTS whenever possible. All options set using IPV6_RTHDRDSTOPTS will be ignored when sending packets unless a routing header is also defined. |
IPV6_TCLASS | Set the outgoing traffic class. This option is
supported for sockets with an address family of AF_INET6 only. An option_value parameter of type int is used to set this value. A value of -1 (default) indicates the default kernel traffic class will be used. A value in the range of 0 to 255, inclusive, indicates the traffic class to be used. Any other value is invalid. |
IPV6_UNICAST_HOPS | Set the hop limit value that will be used for
subsequent unicast packets sent by this socket. This option
is supported for sockets with an address family of AF_INET6 only. An option_value parameter of type int is used to set this value between 0 and 255. |
IPV6_USE_MIN_MTU | Set Path MTU discovery.
This option is supported for sockets with an address family of
AF_INET6. An option_value parameter of type int is used to set this value. A value of -1 (default) indicates the application will inform TCP to perform path MTU discovery for unicast destinations but not perform it for multicast destinations. A value of 0 indicates TCP will always perform path MTU discovery. A value of 1 indicates TCP will always disable path MTU discovery and send packets at the minimum MTU. |
IPV6_V6ONLY | Set the AF_INET6 communication
restrictions. This option is supported for sockets with an address family of
AF_INET6 only. An option_value parameter of type int is used to set this value. A value of 0 (default) disables the option. A non-zero value sets the option meaning that this AF_INET6 socket is restricted to IPv6 communications only. |
MCAST_BLOCK_SOURCE | Block data from a given source to a given group.
To unblock the data use the MCAST_UNBLOCK_SOURCE
option. This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. This structures is defined in <netinet/in.h> as: struct group_source_req { uint32_t gsr_interface; /* interface index */ struct sockaddr_storage gsr_group; /* group address */ struct sockaddr_storage gsr_source; /* source address */ };The gsr_interface field specifies the index of the interface. The gsr_group field specifies the group address. The gsr_source field specifies the source address. |
MCAST_JOIN_GROUP | Join an any-source group.
To leave the any-source group use the MCAST_LEAVE_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_req is used to set this value. The structure is defined in <netinet/in.h> as: struct group_req { uint32_t gr_interface; /* interface index */ struct sockaddr_storage gr_group; /* group address */ };The gr_interface field specifies the index of the interface. The gr_group field specifies the group address. |
MCAST_JOIN_SOURCE_GROUP | Join a source-specific group.
To leave the source-specific group use the MCAST_LEAVE_SOURCE_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. See MCAST_BLOCK_SOURCE for more information about the group_source_req structure. |
MCAST_LEAVE_GROUP | Leave an any-source group.
To join the any-source group use the MCAST_JOIN_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_req is used to set this value. See MCAST_JOIN_GROUP for more information about the group_req structure. |
MCAST_LEAVE_SOURCE_GROUP | Leave a source-specific group.
To join a source-specific group use the MCAST_JOIN_SOURCE_GROUP option.
This option is supported for sockets of type SOCK_DGRAM or
SOCK_RAW only. An option_value parameter of type struct group_source_req is used to set this value. See MCAST_BLOCK_SOURCE for more information about the group_source_req structure. |
MCAST_UNBLOCK_SOURCE | Unblock data from a given source to a given group.
To block the data use the MCAST_BLOCK_SOURCE option. This option is supported
for sockets of type SOCK_DGRAM or SOCK_RAW
only. An option_value parameter of type struct group_source_req is used to set this value. See MCAST_BLOCK_SOURCE for more information about the group_source_req structure. |
Socket Options That Apply to the ICMPv6 Layer (IPPROTO_ICMPV6)
Option | Description and Option Value |
---|---|
ICMP6_FILTER | Set the ICMPv6 Type Filtering. This option is only
supported for sockets with an address family of AF_INET6 and type
of SOCK_RAW with a protocol of IPPROTO_ICMPV6. An option_value parameter of type struct icmp6_filter is used to set this value. This structure is defined in <netinet/icmp6.h> as: struct icmp6_filter { uint32_t icmp6_filt[8]; /* 8*32 = 256 bits */ };The following macros, defined in <netinet/icmp6.h>, can be used to update the type filtering structure to specify wheter or not specific ICMPv6 message types will be passed to the application or be blocked: ICMP6_FILTER_SETPASS, ICMP6_FILTER_SETBLOCK, ICMP6_FILTER_SETPASSALL, and ICMP6_FILTER_SETBLOCKALL. The default is to pass all ICMPv6 message types to the application. |
setsockopt() returns an integer. Possible values are:
When setsockopt() fails, errno can be set to one of the following:
Address already in use. This error code indicates that the socket_descriptor parameter specified for the IP_ADD_MEMBERSHIP operation is already a member of the specified multicast group.
Address not available. For the IP_ADD_MEMBERSHIP or IP_DROP_MEMBERSHIP operations, this error code indicates that an incorrect address was specified for either the imr_multiaddr or imr_interface parameter value.
Descriptor not valid.
Connection ended abnormally.
This error code indicates that the transport provider ended the connection abnormally because of one of the following:
Bad address.
The system detected an address which was not valid while attempting to access the option_value parameter.
Parameter not valid.
This error code indicates one of the following:
Input/output error.
There is not enough buffer space for the requested operation.
The protocol does not support the specified option.
This error code indicates one of the following:
Requested operation requires a connection.
This error code is only returned if the level parameter specifies a level other than SOL_SOCKET and the socket_descriptor parameter points to a socket that is using a connection-oriented transport service that has had its connection broken.
The specified descriptor does not reference a socket.
Operation not supported.
Operation not permitted.
The executing user profile must have *IOSYSCFG special authority to get options when:
The operation would have exceeded the maximum number of references allowed for this socket.
The protocol required to support the specified address family is not available at this time.
Unknown system state.
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
CPFA081 E | Unable to set return value or error code. |
Notes: