getsockopt

Returns the current parameters for the specified socket.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <sys/socket.h>
  #include <netinet/in.h> 
   
  int getsockopt (
     int       s,   
     int       level,   
     int       optname,   
     void     *optval,   
     size_t   *optlen);
  

Parameters

s

(IN) Specifies the socket file handle for which parameters are to be returned.

level

(IN) Specifies the protocol level at which the option resides with one of the following flags:

Flag

Value

Description

IPPROTO_IP

0

Specifies IP level options

IPPROTO_TCP

6

Specifies TCP level options

SOL_SOCKET

0xFFFF

Specifies socket level options

optname

(IN) Specifies the option for the request. See one of the following:

optval

(OUT) Points to the location of an option value. The data type of the option value matches the type used by the option requested with the optname parameter.

optlen

(IN/OUT) Points to a value describing the option’s length.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The socket parameter is not a valid socket file handle.

9

EINVAL

The optlen parameter contains an inappropriate value.

38

ENOTSOCK

The socket parameter does not reference a socket.

42

ENOPROTOOPT

The option is unknown at the level indicated.

Remarks

Options exist at either the socket level or the underlying protocol level. The following options are recognized at the socket level. Except as noted, each can be examined by calling getsockopt and set by calling the setsockopt function.