Gets options on sockets.
Standard C Library (libc.a)
#include <sys/socket.h>
int getsockopt (Socket, Level, OptionName, OptionValue, OptionLength)
int Socket, Level, OptionName;
void * OptionValue;
socklen_t * OptionLength;
The getsockopt subroutine allows an application program to query socket options. The calling program specifies the name of the socket, the name of the option, and a place to store the requested information. The operating system gets the socket option information from its internal data structures and passes the requested information back to the calling program.
Options can exist at multiple protocol levels. They are always present at the uppermost socket level. When retrieving socket options, specify the level where the option resides and the name of the option.
All applications containing the getsockopt subroutine must be compiled with the _BSD macro set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.
Item | Description |
---|---|
Socket | Specifies the unique socket name. |
Level | Specifies the protocol level where the option resides. Options
can be retrieved at the following levels:
|
OptionName | Specifies a single option. The OptionName parameter
and any specified options are passed uninterpreted to the appropriate
protocol module for interpretation. The sys/socket.h file contains
definitions for socket level options. The netinet/tcp.h file
contains definitions for TCP protocol level options. Socket-level
options can be enabled or disabled; they operate in a toggle fashion.
The sys/atmsock.h file contains definitions for ATM protocol
level options. The following list defines socket protocol level options found in the sys/socket.h file:
|
OptionName (contd) |
|
OptionName (contd) |
The following list defines TCP protocol level options found in the netinet/tcp.h file:
|
OptionName (contd) |
The following list defines ATM protocol level options found in the sys/atmsock.h file:
|
OptionValue | Specifies a pointer to the address of a buffer. The OptionValue parameter
takes an integer parameter. The OptionValue parameter should
be set to a nonzero value to enable a Boolean option or to a value
of 0 to disable the option. The following options enable and disable
in the same manner:
|
OptionLength | Specifies the length of the OptionValue parameter. The OptionLength parameter initially contains the size of the buffer pointed to by the OptionValue parameter. On return, the OptionLength parameter is modified to indicate the actual size of the value returned. If no option value is supplied or returned, the OptionValue parameter can be 0. |
Options at other protocol levels vary in format and name.
Item | Description |
---|---|
IP_DONTFRAG | Get current IP_DONTFRAG option value. |
IP_FINDPMTU | Get current PMTU value. |
IP_PMTUAGE | Get current PMTU time out value. |
Item | Description |
---|---|
IP_DONTGRAG | Not supported. |
IP_FINDPMTU | Get current PMTU value. |
IP_PMTUAGE | Not supported. |
Item | Description | Value | |
---|---|---|---|
IPV6_V6ONLY | Determines whether the socket is restricted to IPv6 communications only. |
|
|
Allows the user to determine the outgoing hop limit value for unicast IPv6 packets. |
|
||
Allows the user to determine the outgoing hop limit value for multicast IPv6 packets. |
|
||
Allows the user to determine the interface being used for outgoing multicast packets. |
|
||
If a multicast datagram is sent to a group that the sending host belongs, a copy of the datagram is looped back by the IP layer for local delivery (if the option is set to 1). If the option is set to 0, a copy is not looped back. |
|
||
Determines whether the destination IPv6 address and arriving interface index of incoming IPv6 packets are being received as ancillary data on UDP and raw sockets. |
|
||
Determines whether the hop limit of incoming IPv6 packets is being received as ancillary data on UDP and raw sockets. |
|
||
Determines whether the traffic class of incoming IPv6 packets is being received as ancillary data on UDP and raw sockets. |
|
||
Determines whether the routing header of incoming IPv6 packets is being received as ancillary data on UDP and raw sockets. |
|
||
Determine whether the hop-by-hop options header of incoming IPv6 packets is being received as ancillary data on UDP and raw sockets. |
|
||
Determines whether the destination options header of incoming IPv6 packets is being received as ancillary data on UDP and raw sockets. |
|
||
Determines the source IPv6 address and outgoing interface index for all IPv6 packets being sent on this socket. |
|
||
Determines the next hop being used for outgoing IPv6 datagrams on this socket. |
|
||
Determines the traffic class for outgoing IPv6 datagrams on this socket. |
|
||
Determines the routing header to be used for outgoing IPv6 datagrams on this socket. |
|
||
Determines the hop-by-hop options header to be used for outgoing IPv6 datagrams on this socket. |
|
||
Determines the destination options header to be used for outgoing IPv6 datagrams on this socket. This header will follow a routing header (if present) and will also be used when there is no routing header specified. |
|
||
Determines the destination options header to be used for outgoing IPv6 datagrams on this socket. This header will precede a routing header (if present). If no routing header is specified, this option will be silently ignored. |
|
||
Determines how IPv6 path MTU discovery is being controlled for this socket. |
|
||
Determines whether fragmentation of outgoing IPv6 packets has been disabled on this socket. |
|
||
Determines whether IPV6_PATHMTU messages are being received as ancillary data on this socket. |
|
||
Gets the address selection preferences for a socket. |
|
||
Determines the current Path MTU for a connected socket. |
|
Item | Description | Value |
---|---|---|
IPPROTO_ICMPV6 | Allows the user to filter ICMPV6 messages by the ICMPV6 type field. If no filter was set, the default kernel filter will be returned. |
|
Upon successful completion, the getsockopt subroutine returns a value of 0.
If the getsockopt subroutine is unsuccessful, the subroutine handler performs the following actions:
Upon successful completion of the IPPROTO_IP option IP_PMTUAGE the returns are:
Prior to AIX 5.3:
Beginning with AIX 5.3:
Upon successful completion of TCP protocol sockets option IP_FINDPMTU the returns are:
Prior to AIX 5.3:
Beginning with AIX 5.3:
Item | Description |
---|---|
EBADF | The Socket parameter is not valid. |
EFAULT | The address pointed to by the OptionValue parameter is not in a valid (writable) part of the process space, or the OptionLength parameter is not in a valid part of the process address space. |
EINVAL | The Level, OptionName, or OptionLength is invalid. |
ENOBUF | Insufficient resources are available in the system to complete the call. |
ENOTSOCK | The Socket parameter refers to a file, not a socket. |
ENOPROTOOPT | The option is unknown. |
EOPNOTSUPP | The option is not supported by the socket family or socket type. |
EPERM | The user application does not have the permission to get or to set this socket option. Check the network tunable option. |
The following program fragment illustrates the use of the getsockopt subroutine to determine an existing socket type:
#include <sys/types.h>
#include <sys/socket.h>
int type;
socklen_t size = sizeof(int);
if(getsockopt(s, SOL_SOCKET, SO_TYPE, (void*)&type,&size)<0){
.
.
.
}