setsockopt()

The socket call sets options associated with a socket.

Syntax

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

Parameters

s

level optname optval optlen

Description

This call provides an application program with the means to control a socket communication. The setsockopt() call can be used to set options associated with a socket, such as enabling debugging at the socket or protocol level, controlling timeouts, or permitting socket data broadcasts. Options can exist at the socket or the protocol level; options are always present at the highest socket level. When setting socket options, the level of the option and the name of the option must be specified. 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 and optlen parameters are used to pass data used by the particular set command. The optval parameter points to a buffer containing the data needed by the set command. The optval parameter is optional and if data is not needed by the command, can be set to the NULL pointer. The optlen parameter must be set to the size of the data or data type pointed to by optval. For socket options that are toggles, the option is enabled if optval is nonzero and disabled if optval is 0.

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

Supported setsockopt() Socket Options for SOL_SOCKET

┌─────────────────────────────────────────────────────────────────────┐
│Option Name     Description             Domains(*)  Data     Boolean │
│                                                    Type     or Value│
├─────────────────────────────────────────────────────────────────────┤
│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           int      Boolean │
├─────────────────────────────────────────────────────────────────────┤
│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_OOBINLINE    Leave received OOB data I           int      Boolean │
│                in-line                                              │
├─────────────────────────────────────────────────────────────────────┤
│SO_RCVBUF       Receive buffer size     I, L, N     int      Value   │
├─────────────────────────────────────────────────────────────────────┤
│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 address and I           int      Boolean │
│                port reuse                                           │
├─────────────────────────────────────────────────────────────────────┤
│SO_SNDBUF       Send buffer size        I, L, N     int      Value   │
├─────────────────────────────────────────────────────────────────────┤
│SO_SNDLOWAT     Send low watermark      I, L        int      Value   │
├─────────────────────────────────────────────────────────────────────┤
│SO_SNDTIMEO     Send timeout            I, L        struct   Value   │
│                                                    timeval          │
├─────────────────────────────────────────────────────────────────────┤
│SO_USELOOPBACK  Bypass hardware when    I           int      Value   │
│                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 _ BROADCAST SO _ DEBUG SO _ DONTROUTE SO _ KEEPALIVE SO _ LINGER