SETSOCKOPT(3POSIX)
πΈ hey bestie, welcome to SETSOCKOPT(3POSIX) πΈ
okay so before we even get into it β this page is part of the POSIX Programmer's Manual. The header says SETSOCKOPT(3POSIX) and honestly that's the whole vibe check right there. But listen: the Linux implementation of this interface may differ (so if you're on Linux, go read the corresponding Linux manual page, fr, don't come for me), or the interface might not even be implemented on Linux at all. π
β¨ 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 on Linux behavior β or the interface may not be implemented on Linux at all. Not me warning you twice, but here we are. π«Ά
π NAME π
setsockopt β set the socket options. that's it, that's the girl.
π SYNOPSIS π
#include <sys/socket.h>
int setsockopt(int socket, int level, int option_name,
const void *option_value, socklen_t option_len);
π¦ DESCRIPTION π¦
okay so the setsockopt() function shall set the option specified by the option_name argument, at the protocol level specified by the level argument, to the value pointed to by the option_value argument β for the socket associated with the file descriptor specified by the socket argument. iconic behavior honestly.
The level argument specifies the protocol level at which the option resides. Wanna set options at the socket level? Then you pass level as SOL_SOCKET. Setting options at other levels? Then supply the appropriate level identifier for the protocol controlling the option. For example, to indicate that an option is interpreted by the TCP (Transport Control Protocol), set level to IPPROTO_TCP as defined in the <netinet/in.h> header. periodt.
The option_name argument specifies a single option to set. It can be one of the socket-level options defined in <sys_socket.h> and described in Section 2.10.16, Use of Options.
β οΈ okay important, pay attention bestie: ifoption_nameis equal toSO_RCVTIMEOorSO_SNDTIMEOand the implementation supports setting the option, it is unspecified whether thestruct timevalpointed to byoption_valueis stored as provided by this function or is rounded up to align with the resolution of the clock being used.
π¨ and ALSO: ifsetsockopt()is called withoption_nameequal toSO_ACCEPTCONN,SO_ERROR, orSO_TYPE, the behavior is unspecified. don't do it. that's not your moment.
π₯ RETURN VALUE π₯
Upon successful completion, setsockopt() shall return 0. Otherwise, -1 shall be returned and errno set to indicate the error. classic.
π ERRORS π
The setsockopt() function shall fail if:
EBADFβ Thesocketargument is not a valid file descriptor. πEDOMβ The send and receive timeout values are too big to fit into the timeout fields in the socket structure. they're giving... too much.EINVALβ The specified option is invalid at the specified socket level or the socket has been shut down.EISCONNβ The socket is already connected, and a specified option cannot be set while the socket is connected. it's taken, babe.ENOPROTOOPTβ The option is not supported by the protocol.ENOTSOCKβ Thesocketargument does not refer to a socket. bestie that's not a socket π
The setsockopt() function may fail if:
ENOMEMβ There was insufficient memory available for the operation to complete.ENOBUFSβ Insufficient resources are available in the system to complete the call.
ngl the following sections are informative. slay.
π EXAMPLES π
None.
(not a single one. the girls are resting. π)
π§ APPLICATION USAGE π§
The setsockopt() function provides an application program with the means to control socket behavior. An application program can use setsockopt() to allocate buffer space, control timeouts, or permit socket data broadcasts. The <sys/socket.h> header defines the socket-level options available to setsockopt(). so many options, so little time. β¨
Options may exist at multiple protocol levels. The SO_ options are always present at the uppermost socket level. lowkey the main characters of the option world.
π RATIONALE π
None.
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
- Section 2.10, Sockets
bind()endprotoent()getsockopt()socket()
And from The Base Definitions volume of POSIX.1β2017:
<netinet_in.h><sys_socket.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
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.opengroup.org/unix/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 .
and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017 β the SETSOCKOPT(3POSIX) girls. go set some socket options, you ate. π
β¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms