# getsockopt

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           getsockopt — get the socket options
    


## SYNOPSIS



           #include <sys/socket.h>
    
           int getsockopt(int _socket_ , int _level_ , int _option_name,_
               void *restrict _option_value_ , socklen_t *restrict _option_len_);
    


## DESCRIPTION



           The _getsockopt_() function manipulates options associated with a
           socket.
    
           The _getsockopt_() function shall retrieve the value for the option
           specified by the _option_name_ argument for the socket specified by
           the _socket_ argument. If the size of the option value is greater
           than _option_len_ , the value stored in the object pointed to by the
           _option_value_ argument shall be silently truncated. Otherwise, the
           object pointed to by the _option_len_ argument shall be modified to
           indicate the actual length of the value.
    
           The _level_ argument specifies the protocol level at which the
           option resides. To retrieve options at the socket level, specify
           the _level_ argument as SOL_SOCKET. To retrieve options at other
           levels, supply the appropriate level identifier for the protocol
           controlling the option.  For example, to indicate that an option
           is interpreted by the TCP (Transmission Control Protocol), set
           _level_ to IPPROTO_TCP as defined in the _< netinet/in.h>_ header.
    
           The socket in use may require the process to have appropriate
           privileges to use the _getsockopt_() function.
    
           The _option_name_ argument specifies a single option to be
           retrieved. It can be one of the socket-level options defined in
           sys_socket.h(0p) and described in _Section 2.10.16_ , _Use of Options_.
    


## RETURN VALUE



           Upon successful completion, _getsockopt_() shall return 0;
           otherwise, -1 shall be returned and _errno_ set to indicate the
           error.
    


## ERRORS



           The _getsockopt_() function shall fail if:
    
           **EBADF** The _socket_ argument is not a valid file descriptor.
    
           **EINVAL** The specified option is invalid at the specified socket
                  level.
    
           **ENOPROTOOPT**
                  The option is not supported by the protocol.
    
           **ENOTSOCK**
                  The _socket_ argument does not refer to a socket.
    
           The _getsockopt_() function may fail if:
    
           **EACCES** The calling process does not have appropriate privileges.
    
           **EINVAL** The socket has been shut down.
    
           **ENOBUFS**
                  Insufficient resources are available in the system to
                  complete the function.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           None.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *