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
11

NAME

13       getsockopt — get the socket options
14

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

77       None.
78

APPLICATION USAGE

80       None.
81

RATIONALE

83       None.
84

FUTURE DIRECTIONS

86       None.
87

SEE ALSO

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