GETSOCKOPT(3POSIX)
π GETSOCKOPT β get the socket options π
okay bestie, gather round, because this is the POSIX Programmer's Manual page for getsockopt, and she is lowkey a legend. GETSOCKOPT(3POSIX), periodt.
π¨ PROLOG (read this first, fr fr)
This manual page is part of the POSIX Programmer's Manual. Here's the tea:
- The Linux implementation of this interface may differ β so consult the corresponding Linux manual page for the actual Linux behavior, okay?
- Or honestly, the interface may not even be implemented on Linux at all. π
So like, no cap: check your local docs before you trust this blindly. β¨
β¨ 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);
Like. She's five arguments and she's serving. π
π¦ DESCRIPTION π¦
The getsockopt() function manipulates options associated with a socket. Main character energy, honestly.
The getsockopt() function shall retrieve the value for the option specified by the option_name argument for the socket specified by the socket argument. And here's the tricky part, so pay attention:
- If the size of the option value is greater than
option_len, the value stored in the object pointed to by theoption_valueargument shall be silently truncated. (yes, silently. she just does it. no warning. rude but iconic π) - Otherwise, the object pointed to by the
option_lenargument shall be modified to indicate the actual length of the value.
The level argument specifies the protocol level at which the option resides. So:
- To retrieve options at the socket level, specify the
levelargument asSOL_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
leveltoIPPROTO_TCPas defined in the<netinet/in.h>header. πΈ
The socket in use may require the process to have appropriate privileges to use the getsockopt() function. iykyk.
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> and described in Section 2.10.16, Use of Options.
π₯ RETURN VALUE π₯
- Upon successful completion,
getsockopt()shall return0. slay. π - Otherwise,
-1shall be returned anderrnoset to indicate the error. π
π ERRORS π
The getsockopt() function shall fail if:
EBADFβ Thesocketargument 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β Thesocketargument 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.
Not the "shall" versus "may" distinction doing the absolute most. π
The following sections are informative. (translation: the real spec is above, everything below is vibes π«Ά)
π EXAMPLES π
None.
π§ APPLICATION USAGE π§
None.
β RATIONALE β
None.
π FUTURE DIRECTIONS π
None.
π SEE ALSO π
- Section 2.10.16, Use of Options
bind()close()endprotoent()setsockopt()socket()
The Base Definitions volume of POSIX.1β2017, <sys_socket.h>, <netinet_in.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 original GETSOCKOPT(3POSIX) moment. go get those socket options. π
β¨π
π¦ 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