getsockopt()--Retrieve Information about Socket Options


  BSD 4.3 Syntax
  #include <sys/types.h>
  #include <sys/socket.h>

 int getsockopt(int socket_descriptor,
                int level,
                int option_name,
                char *option_value,
                int *option_length)


  Service Program Name: QSOSRV1

  Default Public Authority: *USE

  Threadsafe: Yes



  UNIX® 98 Compatible Syntax
  #define _XOPEN_SOURCE 520
  #include <sys/socket.h>

 int getsockopt(int socket_descriptor,
                int level,
                int option_name,
                void *option_value,
                socklen_t *option_length)


  Service Program Name: QSOSRV1

  Default Public Authority: *USE

  Threadsafe: Yes


The getsockopt() function is used to retrieve information about 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.


Parameters

socket_descriptor
(Input) The descriptor of the socket for which information is to be retrieved.

level
(Input) Value indicating whether the request applies to the socket itself or to the underlying protocol being used. Supported values are:

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.

option_name
(Input) The option name for which information is to be retrieved. The following tables under option_value list the options supported for each level. Assume that the option is supported for all address families unless described otherwise.

Note: Options directed to a specific protocol level are only supported by that protocol. An option that is directed to level SOL_SOCKET usually completes successfully. If the underlying protocol does not provide support for the option, the socket library retrieves one of the following:

This provides compatibility with Berkeley Software Distributions implementations that also shield the application from protocols that do not support an option.


option_value
(Output) A pointer to the option value. The following tables list the options with details on the structure type passed for the option_value pointer.

Socket Options That Apply to the IP Layer (IPPROTO_IP)

Option Description and Option Value
IP_DONTFRAG Return the current don't fragment flag setting 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 retrieve this value. A value of 0 (default) indicates the option is disabled. A value of 1 indicates the option is set meaning the kernel will discard the packet instead of inserting the fragment header.
IP_MULTICAST_IF Get interface over which outgoing multicast datagrams will 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 retrieve 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 will be sent.
IP_MULTICAST_LOOP Determine the multicast looping mode. 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 retrieve the current setting. A non-zero value (default) indicates that multicast datagrams sent by this system will also be delivered to this system as long as it is a member of the multicast group. A value of 0x00 indicates the option is disabled meaning a copy of the datagram will not be delivered to the sending host.
IP_MULTICAST_TTL Get Time To Live (TTL) from 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 retrieve the setting which is between 0 and 255.
IP_OPTIONS Determine what options are set in the IP header. This is only supported for sockets with an address family of AF_INET.

For the IP_OPTIONS option, option_value is a pointer to storage in which data representing the IP options (as specified in RFC 791) is stored. getsockopt() returns the options in the following format:

IP address IP options ... IP options

IP address is a 4-byte IP address, and IP options identifies the IP options that were set using setsockopt(). If an IP option set using setsockopt() contained a source routing option (strict or loose), the first IP address in the source routing option list is removed. The IP options are adjusted accordingly. (For this adjustment, the length in the IP options portion is changed, and alignment is kept by adding no-operation option). The buffer is returned in the same format. The first 4 bytes are the IP address that was removed, and this is followed by the remaining IP options, if any. If the IP options portion does not contain a source routing option, the first 4 bytes are set to zero.

For the IP_MULTICAST_IF option, option_value is a pointer to storage in which the structure in_addr, defined in <netinet/in.h> as the following, will be stored:

   struct in_addr {
      u_long  s_addr; /* IP address  */
    };

The s_addr field that is returned will be the local IP address that is associated with the interface over which outgoing multicast datagrams are being sent.

Notes:

  1. For sockets that use a connection-oriented transport service, IP options that are set using setsockopt() are only used if they are set prior to a connect() being issued. After the connection is established, any IP options that the user sets are ignored.

  2. If the IP options portion contains a source routing option, then the address in the source routing option overrides the destination address. The destination address may have been specified on an output operation (for example, on a sendto()) or on a connect().

  3. If a socket has a type of SOCK_RAW and a protocol of IPPROTO_RAW, any IP options set using setsockopt() are ignored (since the user must supply the IP header data on an output operation as part of the data that is being transmitted).

  4. The structure ip_opts (defined in <netinet/in.h>) can be used to receive IP options.

IP_RECVLCLIFADDR Determine if the local interface that a datagram was received will 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 retrieve this value. A value of 0 (default) indicates the option is disabled. A value of 1 indicates the option is enabled meaning the first 4 bytes of the reserved field of the sockaddr structure will contain the local interface.
Start of V7R1 changesIP_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 retrieve this value. A value of 0 (default) indicates the option is disabled. A non-zero value indicates the option is set, meaning ancillary data for IP_PKTINFO will be received on recvmsg(). End of V7R1 changes
IP_TOS Get 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 retrieve this value.

Note: Only the rightmost octet (least significant octet) of the integer value is used.

IP_TTL Get Time To Live (TTL) 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 retrieve this value.

Note:Only the rightmost octet (least significant octet) of the integer value is used.



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 is used in place of the TCP attribute TCPKEEPALV whenever 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 retrieve 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 non-zero value indicates the time in seconds TCP will wait before sending out a probe to the other side of the connection.
TCP_MAXSEG Determine TCP maximum segment size. This option is only supported for sockets with an address family of AF_INET or AF_INET6 and type SOCK_STREAM.

An option_value parameter of type unsigned int is used to retrieve this value.
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 SOCK_STREAM.

An option_value parameter of type int is used to retrieve this value. A value of 0 (default) indicates the option is disabled meaning TCP will follow the Nagle algorithm. A non-zero indicates the option is enabled 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_ACCEPTCONN Reports whether socket listening is enabled or not.

An option_value parameter of type int is used to retrieve this value. This is a boolean option. A value of 0 indicates socket listening is not enabled. A value of 1 indicates socket listening is enabled.
SO_ACCEPTECONNABORTED Determine if the listening socket will return ECONNABORTED when a connection on the listening backlog is reset prior to a blocking accept(). The option is only valid on a socket that has successfully issued the listen() call. The option has no effect on non-blocking sockets. 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 retrieve this value. A value of 0 (default) indicates the optionis disabled. A non-zero value indcates the option is enabled meaning a blocking accept() will return ECONNABORTED when a connection on the listening backlog is reset prior to the blocking accept().
Start of V7R1 changes SO_ACCEPTEPERM Determine if the listening socket will return EPERM when a connection on the listening socket is rejected by a user exit program registered for QIBM_QSO_ACCEPT. This applies to any sockets API that accepts connections. 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 retrieve this value. A value of 0 (default) indicates the option is disabled 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 indicates the option is enabled meaning rejected incoming connections will result in the sockets API that tried to accept the connection to return -1 with errno set to EPERM.End of V7R1 changes
SO_BROADCAST Determine if messages can be sent to the 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 can be determined by issuing an ioctl() specifying the SIOCGIFBRDADDR request.

An option_value parameter of type int is used to retrieve this value. A value of 0 (default) indicated the option is disabled. A non-zero value indicated the option is enabled allowing the socket to issue messages to a broadcast address.
SO_DEBUG Determine if low level-debugging is active.

An option_value parameter of type int is used to retrieve this value. A value of 0 (default) indicates the option is disabled. A non-zero value indicates the option is enabled meaning low level-debugging is active.
SO_DONTROUTE Determine if the normal routing mechanism is being bypassed. 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 retrieve this value. A value of 0 (default) indicates the option is disabled. A non-zero value indicates the option is enabled meaning normal routing mechanisms should be bypassed.
SO_ERROR Return any pending errors in the socket.

An option_value parameter of type int is used to retrieve this value. The value returned corresponds to the standard error codes defined in <errno.h>
SO_KEEPALIVE Determine if the connection is being kept up by periodic transmissions. This option is only supported for sockets with an address family of AF_INET or AF_INET6 and type SOCK_STREAM.

An option_value parameter of type int is used to retrieve this value. A value of 0 (default) indicates the option is disabled. A non-zero value indicates the option is enabled meaning TCP should keep the connection up by sending periodic transmissions.
SO_LINGER Determine whether the system attempts to deliver 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 retrieve 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 non-zero 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():

  • For AF_INET and AF_INET6 sockets:

    • If the l_onoff value is zero, the system attempts to send any buffered data with an infinite wait-time.

    • If the l_onoff value is non-zero and the l_linger value is non-zero, the system attempts to send any buffered data for l_linger time. If l_linger time has elapsed and the data is still not successfully sent, it is discarded. When data is discarded, the remote program may receive a [ECONNRESET].

  • For AF_INET sockets over SNA:

    • If the l_onoff value is non-zero and the l_linger value is zero, the system waits indefinitely (no timer is implemented). Otherwise, if the l_onoff value is non-zero and the l_linger value is zero, the system discards any buffered data. When data is discarded, the remote program may receive a [ECONNRESET].

Note: An application must implement an application level confirmation. Guaranteed receipt of data by the partner program is required. Setting SO_LINGER does not guarantee delivery.

SO_OOBINLINE Determine if 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 retrieve this value. A value of 0 (default) indicates the option is disabled. A non-zero value indicates the option is enabled meaning out-of-band data is received inline with normal data.
SO_RCVBUF Determine the size of the receive buffer.

An option_value parameter of type int is used to retrieve this value.
SO_RCVLOWAT Determine 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 retrieve this value. The default size is 1.
SO_RCVTIMEO Determine 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 retrieve 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 Determine 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 retrieve this value. A value of 0 (default) indicates the option is disabled. A non-zero value indicates the option is enabled meaning the local socket address can be reused.
SO_SNDBUF Determine the size of the send buffer.

An option_value parameter of type int is used to retrieve this value.
SO_SNDLOWAT Determine the size of the send low-water mark. This option is not supported.
SO_SNDTIMEO Determine 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 retrieve 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_TYPE Determine the value for the socket type.

An option_value parameter of type int is used to retrieve this value.
SO_USELOOPBACK Determine 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
Start of V7R1 changes IPV6_ADDR_PREFERENCES Determine 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 retrieve the current setting. A value of 0 (default) means the option is disabled and default source address selection rules will be used. A non-zero value indicates the flag combination specifying the source address selection preferences that will be used.

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 */
End of V7R1 changes
IPV6_CHECKSUM Determine 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 retrieve the current setting. 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.
IPV6_DONTFRAG Determine 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 retrieve this value. A value of 0 means the option is disabled and the default of automatic insertion will be used. A non-zero value indicates that the option is set meaning the kernel will discard the packet instead of inserting the fragment header.
IPV6_DSTOPTS Get the current settings for the destination options following the routing header (or when no routing header exists) for the socket. 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 retrieve 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.
A zero value for option_length on return indicates that no header exists.
IPV6_HOPOPTS Get the current settings for the hop-by-hop options header for this socket. 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 retrieve 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.
A zero value for option_length on return indicates that no header exists.
IPV6_MULTICAST_HOPS Get 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 retrieve the current setting which is a vlaue between 0 and 255. The default is 1.
IPV6_MULTICAST_IF Get 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 retrieve the interface index that is associated with the interface over which outgoing multicast datagrams will be sent.
IPV6_MULTICAST_LOOP Determine 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 retrieve 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 Get the current settings for the next hop address. 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 retrieve 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.
A zero value for option_length on return indicates that a next hop address has not been set.

Notes:

  1. This option will be ignored for multicast destinations because it has no meaning for them.
  2. If an interface is defined by IPV6_PKTINFO in addition to this option, the next hop must be reachable through the specified interface.

IPV6_PATHMTU Get the current path MTU value for the destination currently connected to. This option is supported for connected sockets with an address family of AF_INET6 only.

An option_value parameter of type ip6_mtuinfo is used to retrieve this value. The structre is defined in <netinet/in.h> as:

  struct ip6_mtuinfo {
    struct sockaddr_in6 ip6m_addr; /* Dst addr including zone ID   */
    uint32_t            ip6m_mtu;  /* Path MTU in host byte order  */
  };
The ip6m_addr field specifies the destination address that this socket is connected to.
The ip6m_mtu field specifies the path Maximum Transmission Unit.

Note: This option can only be used for a connected socket, because a non- connected socket does not have the information of the destination and there is no way to pass the destination via getsockopt().
IPV6_PKTINFO Determine the current settings for the socket's default source IPv6 address and 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 retrieve 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.
A value of in6addr_any for ipi6_addr on return indicates the source IPv6 address is not set. A value of zero for ipi6_index on return indicates the interface index is not set.
IPV6_PREFER_TEMPADDR Get the current settings for 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 retrieve the current setting. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set 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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set 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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set 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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set 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 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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set. This means when a sendmsg() is done on a packet that is too big, 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.

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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set 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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set 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 retrieve this value. A value of 0 (default) means the option is disabled. A non-zero value indicates that the option is set meaning ancillary data for IPV6_TCLASS will be received on recvmsg().
IPV6_RTHDR Get the current settings for the routing header for the socket. 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 retrieve 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.
A zero value for option_length on return indicates that no routing header exists.
IPV6_RTHDRDSTOPTS Get the current settings for the destination options header preceding the routing header for the socket. 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 retrieve this value. See IPV6_DSTOPTS for more information about the ip6_dest structure.
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.
All options set using IPV6_RTHDRDSTOPTS will be ignored when sending packets unless a routing header is also defined.
A zero value for option_length on return indicates that no destination options header exists.
IPV6_TCLASS Get the current settings for 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 retrieve the current setting. If this option is -1 (default) the default kernel traffic class will be used. A value in the range of 0 to 255 indicates the traffic class to be used. Any other value is invalid.
IPV6_UNICAST_HOPS Get the hop limit value that will be used for subsequent unicast packets sent by this socket. This option is only supported for sockets with an address family of AF_INET6.

An option_value parameter of type int is used to retrieve the current setting which is between 0 and 255.
IPV6_USE_MIN_MTU Determine if the socket application can control whether or not Path MTU discovery will be used. This option is supported for sockets with an address family of AF_INET6 only.

An option_value parameter of type int is used to retrieve the current setting. If this option is -1 (default) the socket application will perform path MTU discovery for unicast destinations but will not perform it for multicast destinations. A value of 0 indicates the application will always perform path MTU discovery. A value of 1 indicates the application will always disable path MTU discovery and send packets at the minimum MTU.
IPV6_V6ONLY Determine the AF_INET6 communication restrictions. This option is only supported for sockets with an address family of AF_INET6.

An option_value parameter of type int is used to retrieve this value. A value of 0 (default) disables the option. A non-zero value indicates that this AF_INET6 socketis restricted to IPv6 communications only.


Socket Options That Apply to the ICMPv6 Layer (IPPROTO_ICMPV6)

Option Description and Option Value
ICMP6_FILTER Determine the current 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 retrieve 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 after retrieval of the type filtering structure to determine whether or not specific ICMPv6 message types will be passed to the application or be blocked: ICMP6_FILTER_WILLPASS and ICMP6_FILTER_WILLBLOCK.

option_length
(I/O) The length of the option_value. The option_length parameter must be initially set by the caller. option_length is changed on return to indicate the actual amount of storage used.

Note: For option values that are of type integer, the length of the option_value pointed to by the option_length parameter must be set to a value that is greater or equal to the size of an integer. If the length is not set correctly, a correct option value is not received.


Authorities

The user profile for the thread must have *IOSYSCFG special authority to set options when:

Return Value

getsockopt() returns an integer. Possible values are:


Error Conditions

When getsockopt() fails, errno can be set to one of the following:

[EBADF] Descriptor not valid.

[ECONNABORTED] Connection ended abnormally.

This error code indicates that the transport provider ended the connection abnormally because of one of the following:

  • The retransmission limit has been reached for data that was being sent on the socket.

  • A protocol error was detected.
[EFAULT] Bad address.

The system detected an address which was not valid while attempting to access the option_value or option_length parameters.

[EINVAL] Parameter not valid.

This error code indicates one of the following:

  • The level parameter specifies a level that is not supported. (except for when the socket has an address family of AF_UNIX, in which case [ENOPROTOOPT] is returned).

  • The option_name parameter specifies a value that is not valid (except for when the level is SOL_SOCKET , in which case [ENOPROTOOPT] is returned).

  • The option_length parameter points to an integer that has a negative value.
[EIO] Input/output error.

[ENOBUFS] There is not enough buffer space for the requested operation.

[ENOPROTOOPT] The protocol does not support the specified option.

This error code indicates one of the following:

  • The socket has an address family of AF_UNIX and the level parameter specified is not SOL_SOCKET .

  • The level parameter specifies a level of SOL_SOCKET and the option_name parameter specifies a value that is not valid.
[ENOTCONN] 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.

[ENOTSOCK] The specified descriptor does not reference a socket.

[EOPNOTSUPP] Operation not supported.
[EPERM] Operation not permitted.

The executing user profile must have *IOSYSCFG special authority to get options when:

  • the level parameter specifies IPPROTO_IP and the option_value parameter is IP_OPTIONS
  • the level parameter specifies IPPROTO_IPV6 and the option_value parameter is IPV6_NEXTHOP
  • the level parameter specifies IPPROTO_IPV6 and the option_value parameter is IPV6_RTHDR
[EUNKNOWN] Unknown system state.

[EUNATCH] The protocol required to support the specified address family is not available at this time.


Error Messages

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.


Usage Notes

  1. Socket options are defined in <sys/socket.h>, IP options are defined in <netinet/ip.h> and <netinet/in.h>, TCP options are defined in <netinet/tcp.h>, IPv6 and ICMPv6 options are defined in <netinet/in.h>.

  2. When a TCP connection is closed for a socket using the AF_INET or AF_INET6 address families, the port associated with that connection is not made available until twice the Maximum Segment Life (MSL) time in seconds has passed. The MSL time is approximately 2 minutes. The SO_REUSEADDR option allows a bind() to succeed when requesting a port that is being held during this time frame. This can be especially useful if a server is abruptly ended and restarted.

    Notes:

    1. For AF_INET and AF_INET6, SOCK_STREAM sockets, this option does not allow two servers to successfully issue a bind() requesting the same port number and local address combination. For AF_INET and AF_INET6, SOCK_DGRAM sockets, the SO_REUSEADDR option does allow multiple servers to successfully bind to the same port. When broadcast or multicast datagrams are received for a given port, each server that is bound to that port receives a copy of the datagram provided each server has enabled the SO_REUSEADDR option.

    2. This option does not affect unicast datagram delivery.



  3. Issuing a getsockopt() with the SO_ERROR option results in the resetting of the SO_ERROR option to zero. Issuing another getsockopt() with the SO_ERROR option also returns a value of zero, assuming no errors occur on the socket. Other functions, when issued, also reset the SO_ERROR option to zero. These functions are:
  4. When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the getsockopt() API is mapped to qso_getsockopt98().
  5. The following comment applies to the IPV6_RTHDR option value:
  6. The following comment applies to the IPV6_HOPOPTS, IPV6_DSTOPTS, and IPV6_RTHDRDSTOPTS option values:

Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]