getsockopt()

The getsockopt() socket call gets the socket options associated with a socket.

Syntax

#include <types.h>
#include <sys\socket.h>
int getsockopt(s, level, optname, optval, optlen)
int s;
int level;
int optname;
char *optval;
int *optlen;

Parameters

s

level optname optval optlen

Description

This call returns the value of a socket option at the socket or protocol level. It can be called for sockets of all domain types. Some options are supported only for specific socket types. You must specify the level of the option and the name of the option to retrieve option values. The following table lists the supported levels.

Supported Levels

┌─────────────────────────────────────────────────────────────────┐│Supported Level               #define in                         │
├─────────────────────────────────────────────────────────────────┤
│SOL_SOCKET                    <SYS\SOCKET.H>                     │
├─────────────────────────────────────────────────────────────────┤
│IPPROTO_IP                    <NETINET\IN.H>                     │
├─────────────────────────────────────────────────────────────────┤
│IPPROTO_TCP                   <NETINET\IN.H>                     │
├─────────────────────────────────────────────────────────────────┤
│NBPROTO_NB                    <NETNB\NB.H>                       │
└─────────────────────────────────────────────────────────────────┘

The optval parameter is a pointer to the buffer where the option values are returned. The optlen parameter must be initially set to the size of the buffer before calling getsockopt(). On return, the optlen parameter is set to the actual size of the data returned. For socket options that are Boolean, the option is enabled if optval is nonzero and disabled if optval is 0.

The following tables list the supported options for getsockopt() at each level (SOL_SOCKET, IPPROTO_IP, IPPROTO_TCP). Detailed descriptions of the options follow each table.

Supported getsockopt() Socket Options for SOL_SOCKET

┌────────────────────────────────────────────────────────────────────┐
│Option Name     Description             Domains(*) Data     Boolean │
│                                                   Type     or Value│
├────────────────────────────────────────────────────────────────────┤
│SO_ACCEPTCONN   Listen status           I, L       int      Boolean │
├────────────────────────────────────────────────────────────────────┤
│SO_BROADCAST    Allow sending of        I, N       int      Boolean │
│                broadcast messages                                  │
├────────────────────────────────────────────────────────────────────┤
│SO_DEBUG        Turn on recording of    I, L       int      Boolean │
│                debugging information                               │
├────────────────────────────────────────────────────────────────────┤
│SO_DONTROUTE    Bypass routing tables   I, L       int      Boolean │
├────────────────────────────────────────────────────────────────────┤
│SO_ERROR        Return any pending      I, L       int      Value   │
│                error and clear                                     │
├────────────────────────────────────────────────────────────────────┤
│SO_KEEPALIVE    Keep connections alive  I          int      Boolean │
├────────────────────────────────────────────────────────────────────┤
│SO_LINGER       Linger on close if data I          struct   Value   │
│                present                            linger           │
├────────────────────────────────────────────────────────────────────┤
│SO_L_BROADCAST  Limited broadcast sent  I          int      Boolean │
│                on all interfaces                                   │
├────────────────────────────────────────────────────────────────────┤
│SO_OPTIONS      Retrieve socket options I          int      Flags   │
│                (flags)                                             │
├────────────────────────────────────────────────────────────────────┤
│SO_OOBINLINE    Leave received OOB data I          int      Boolean │
│                in-line                                             │
├────────────────────────────────────────────────────────────────────┤
│SO_RCVBUF       Receive buffer size     I, L, N    int      Value   │
├────────────────────────────────────────────────────────────────────┤
│SO_RCV_SHUTDOWN If shutdown called for  I, L       int      Boolean │
│                receive                                             │
├────────────────────────────────────────────────────────────────────┤
│SO_RCVLOWAT     Receive low watermark   I, L       int      Value   │
├────────────────────────────────────────────────────────────────────┤
│SO_RCVTIMEO     Receive timeout         I, L       struct   Value   │
│                                                   timeval          │
├────────────────────────────────────────────────────────────────────┤
│SO_REUSEADDR    Allow local address     I, N       int      Boolean │
│                reuse                                               │
├────────────────────────────────────────────────────────────────────┤
│SO_REUSEPORT    Allow local port reuse  I          int      Boolean │
├────────────────────────────────────────────────────────────────────┤
│SO_SNDBUF       Send buffer size        I, L, N    int      Value   │
├────────────────────────────────────────────────────────────────────┤
│SO_SND_SHUTDOWN If shutdown called for  I, L       int      Boolean │
│                send                                                │
├────────────────────────────────────────────────────────────────────┤
│SO_SNDLOWAT     Send low watermark      I, L       int      Value   │
├────────────────────────────────────────────────────────────────────┤
│SO_SNDTIMEO     Send timeout            I, L       struct   Value   │
│                                                   timeval          │
├────────────────────────────────────────────────────────────────────┤
│SO_TYPE         Socket type             I, L, N    int      Value   │
├────────────────────────────────────────────────────────────────────┤
│SO_USELOOPBACK  Bypass hardware when    I, L       int      Boolean │
│                possible                                            │
└────────────────────────────────────────────────────────────────────┘

Table Note (*) This column specifies the communication domains to which this option applies: I for internet, L for local IPC, and N for NetBIOS.

The following options are recognized for SOL_SOCKET:

Option

SO _ ACCEPTCONN SO _ BROADCAST SO _ DEBUG SO _ DONTROUTE SO _ ERROR SO _ KEEPALIVE SO _ LINGER