SETSOCKOPT(3)              POSIX Programmer's Manual             SETSOCKOPT(3)



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


NNAAMMEE
       setsockopt -- set the socket options

SSYYNNOOPPSSIISS
       #include <sys/socket.h>

       int setsockopt(int _s_o_c_k_e_t, int _l_e_v_e_l, int _o_p_t_i_o_n___n_a_m_e,
           const void *_o_p_t_i_o_n___v_a_l_u_e, socklen_t _o_p_t_i_o_n___l_e_n);

DDEESSCCRRIIPPTTIIOONN
       The _s_e_t_s_o_c_k_o_p_t() function shall set the option specified by the
       _o_p_t_i_o_n___n_a_m_e argument, at the protocol level specified by the _l_e_v_e_l
       argument, to the value pointed to by the _o_p_t_i_o_n___v_a_l_u_e argument for the
       socket associated with the file descriptor specified by the _s_o_c_k_e_t
       argument.

       The _l_e_v_e_l argument specifies the protocol level at which the option
       resides. To set options at the socket level, specify the _l_e_v_e_l argument
       as SOL_SOCKET. To set options at other levels, supply the appropriate
       _l_e_v_e_l identifier for the protocol controlling the option. For example,
       to indicate that an option is interpreted by the TCP (Transport Control
       Protocol), set _l_e_v_e_l to IPPROTO_TCP as defined in the _<_n_e_t_i_n_e_t_/_i_n_._h_>
       header.

       The _o_p_t_i_o_n___n_a_m_e argument specifies a single option to set. It can be
       one of the socket-level options defined in <<ssyyss__ssoocckkeett..hh>> and described
       in _S_e_c_t_i_o_n _2_._1_0_._1_6, _U_s_e _o_f _O_p_t_i_o_n_s.  If _o_p_t_i_o_n___n_a_m_e is equal to
       SO_RCVTIMEO or SO_SNDTIMEO and the implementation supports setting the
       option, it is unspecified whether the ssttrruucctt ttiimmeevvaall pointed to by
       _o_p_t_i_o_n___v_a_l_u_e is stored as provided by this function or is rounded up to
       align with the resolution of the clock being used. If _s_e_t_s_o_c_k_o_p_t() is
       called with _o_p_t_i_o_n___n_a_m_e equal to SO_ACCEPTCONN, SO_ERROR, or SO_TYPE,
       the behavior is unspecified.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _s_e_t_s_o_c_k_o_p_t() shall return 0. Otherwise, -1
       shall be returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       The _s_e_t_s_o_c_k_o_p_t() function shall fail if:

       EEBBAADDFF  The _s_o_c_k_e_t argument is not a valid file descriptor.

       EEDDOOMM   The send and receive timeout values are too big to fit into the
              timeout fields in the socket structure.

       EEIINNVVAALL The specified option is invalid at the specified socket level or
              the socket has been shut down.

       EEIISSCCOONNNN
              The socket is already connected, and a specified option cannot
              be set while the socket is connected.

       EENNOOPPRROOTTOOOOPPTT
              The option is not supported by the protocol.

       EENNOOTTSSOOCCKK
              The _s_o_c_k_e_t argument does not refer to a socket.

       The _s_e_t_s_o_c_k_o_p_t() function may fail if:

       EENNOOMMEEMM There was insufficient memory available for the operation to
              complete.

       EENNOOBBUUFFSS
              Insufficient resources are available in the system to complete
              the call.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _s_e_t_s_o_c_k_o_p_t() function provides an application program with the
       means to control socket behavior. An application program can use
       _s_e_t_s_o_c_k_o_p_t() to allocate buffer space, control timeouts, or permit
       socket data broadcasts. The _<_s_y_s_/_s_o_c_k_e_t_._h_> header defines the socket-
       level options available to _s_e_t_s_o_c_k_o_p_t().

       Options may exist at multiple protocol levels. The SO_ options are
       always present at the uppermost socket level.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._1_0, _S_o_c_k_e_t_s, _b_i_n_d(), _e_n_d_p_r_o_t_o_e_n_t(), _g_e_t_s_o_c_k_o_p_t(), _s_o_c_k_e_t()

       The Base Definitions volume of POSIX.1-2008, <<nneettiinneett__iinn..hh>>,
       <<ssyyss__ssoocckkeett..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                        SETSOCKOPT(3)
