Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Socket options

&pagelevel(3)&pagelevel

You can use the setsockopt() and getsockopt() functions to set or query the current value of various options for sockets.

For example, you set options to activate the keepalive monitoring for a socket connection or to modify the time interval for monitoring.

For example, you can set options to identify a socket for sending broadcast messages.

The general format of the calls is as follows:

setsockopt(s, level, optname, optval, optlen);

getsockopt(s, level, optname, optval, optlen);

s designates the socket for which the option is to be set or queried.
level defines the protocol level to which the option belongs. This is normally the socket level that is indicated by the SOL_SOCKET symbolic constant (for AF_INET and AF_INET6) or SOL_TRANSPORT (for AF_ISO). SOL_SOCKET and SOL_TRANSPORT are defined in <sys.socket.h>.

Other levels are SOL_GLOBAL, IP_PROTO_TCP, IP_PROTO_IPv4, IP_PROTO_IPv6, IPPROTO_ICMP und IPPROTO_ICMPv6. For reasons of compatibility, both IP_PROTO_IP and IP_PROTO_IPv4 are supported. You will find a description of these levels in the description of the getsockopt() and setsockopt() functions in section "getsockopt(), setsockopt() - get and set socket options".

The socket option is specified in optname and is also a symbolic constant defined in <sys.socket.h>.

optval is a pointer to the option value. You use optval with setsockopt() to enable/disable the optname option for socket s. With getsockopt(), optval informs you as to whether the optname option is enabled or disabled for socket s.

With setsockopt(), optlen defines the length of the option value optval, With getsockopt(), optlen is a pointer which defines the size of the memory area to which optval points. On returning from getsockopt(), optlen points to an integer value that indicates the current length of the option value returned in optval.