Next: Socket-Level Options, Up: Socket Options
Here are the functions for examining and modifying socket options. They are declared in sys/socket.h.
The
getsockoptfunction gets information about the value of option optname at level level for socket socket.The option value is stored in a buffer that optval points to. Before the call, you should supply in
*optlen-ptr the size of this buffer; on return, it contains the number of bytes of information actually stored in the buffer.Most options interpret the optval buffer as a single
intvalue.The actual return value of
getsockoptis0on success and-1on failure. The followingerrnoerror conditions are defined:
EBADF- The socket argument is not a valid file descriptor.
ENOTSOCK- The descriptor socket is not a socket.
ENOPROTOOPT- The optname doesn't make sense for the given level.