1GETSOCKOPT(3P)             POSIX Programmer's Manual            GETSOCKOPT(3P)
2
3
4

PROLOG

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

NAME

12       getsockopt — get the socket options
13

SYNOPSIS

15       #include <sys/socket.h>
16
17       int getsockopt(int socket, int level, int option_name,
18           void *restrict option_value, socklen_t *restrict option_len);
19

DESCRIPTION

21       The getsockopt() function manipulates options associated with a socket.
22
23       The getsockopt() function shall retrieve the value for the option spec‐
24       ified  by  the  option_name  argument  for  the socket specified by the
25       socket argument. If the size  of  the  option  value  is  greater  than
26       option_len,   the  value  stored  in  the  object  pointed  to  by  the
27       option_value argument  shall  be  silently  truncated.  Otherwise,  the
28       object pointed to by the option_len argument shall be modified to indi‐
29       cate the actual length of the value.
30
31       The level argument specifies the protocol level  at  which  the  option
32       resides.  To  retrieve  options  at the socket level, specify the level
33       argument as SOL_SOCKET. To retrieve options at other levels, supply the
34       appropriate  level  identifier for the protocol controlling the option.
35       For example, to indicate that an  option  is  interpreted  by  the  TCP
36       (Transmission Control Protocol), set level to IPPROTO_TCP as defined in
37       the <netinet/in.h> header.
38
39       The socket in use may require the process to  have  appropriate  privi‐
40       leges to use the getsockopt() function.
41
42       The  option_name argument specifies a single option to be retrieved. It
43       can be one of the socket-level options defined  in  <sys_socket.h>  and
44       described in Section 2.10.16, Use of Options.
45

RETURN VALUE

47       Upon  successful completion, getsockopt() shall return 0; otherwise, -1
48       shall be returned and errno set to indicate the error.
49

ERRORS

51       The getsockopt() function shall fail if:
52
53       EBADF  The socket argument is not a valid file descriptor.
54
55       EINVAL The specified option is invalid at the specified socket level.
56
57       ENOPROTOOPT
58              The option is not supported by the protocol.
59
60       ENOTSOCK
61              The socket argument does not refer to a socket.
62
63       The getsockopt() function may fail if:
64
65       EACCES The calling process does not have appropriate privileges.
66
67       EINVAL The socket has been shut down.
68
69       ENOBUFS
70              Insufficient resources are available in the system  to  complete
71              the function.
72
73       The following sections are informative.
74

EXAMPLES

76       None.
77

APPLICATION USAGE

79       None.
80

RATIONALE

82       None.
83

FUTURE DIRECTIONS

85       None.
86

SEE ALSO

88       Section  2.10.16,  Use of Options, bind(), close(), endprotoent(), set‐
89       sockopt(), socket()
90
91       The  Base   Definitions   volume   of   POSIX.1‐2017,   <sys_socket.h>,
92       <netinet_in.h>
93
95       Portions  of  this text are reprinted and reproduced in electronic form
96       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
97       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
98       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
99       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
100       event of any discrepancy between this version and the original IEEE and
101       The  Open Group Standard, the original IEEE and The Open Group Standard
102       is the referee document. The original Standard can be  obtained  online
103       at http://www.opengroup.org/unix/online.html .
104
105       Any  typographical  or  formatting  errors that appear in this page are
106       most likely to have been introduced during the conversion of the source
107       files  to  man page format. To report such errors, see https://www.ker
108       nel.org/doc/man-pages/reporting_bugs.html .
109
110
111
112IEEE/The Open Group                  2017                       GETSOCKOPT(3P)
Impressum