1GETPEERNAME(3P) POSIX Programmer's Manual GETPEERNAME(3P)
2
3
4
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
12 getpeername — get the name of the peer socket
13
15 #include <sys/socket.h>
16
17 int getpeername(int socket, struct sockaddr *restrict address,
18 socklen_t *restrict address_len);
19
21 The getpeername() function shall retrieve the peer address of the spec‐
22 ified socket, store this address in the sockaddr structure pointed to
23 by the address argument, and store the length of this address in the
24 object pointed to by the address_len argument.
25
26 The address_len argument points to a socklen_t object which on input
27 specifies the length of the supplied sockaddr structure, and on output
28 specifies the length of the stored address. If the actual length of
29 the address is greater than the length of the supplied sockaddr struc‐
30 ture, the stored address shall be truncated.
31
32 If the protocol permits connections by unbound clients, and the peer is
33 not bound, then the value stored in the object pointed to by address is
34 unspecified.
35
37 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
38 returned and errno set to indicate the error.
39
41 The getpeername() function shall fail if:
42
43 EBADF The socket argument is not a valid file descriptor.
44
45 EINVAL The socket has been shut down.
46
47 ENOTCONN
48 The socket is not connected or otherwise has not had the peer
49 pre-specified.
50
51 ENOTSOCK
52 The socket argument does not refer to a socket.
53
54 EOPNOTSUPP
55 The operation is not supported for the socket protocol.
56
57 The getpeername() function may fail if:
58
59 ENOBUFS
60 Insufficient resources were available in the system to complete
61 the call.
62
63 The following sections are informative.
64
66 None.
67
69 None.
70
72 None.
73
75 None.
76
78 accept(), bind(), getsockname(), socket()
79
80 The Base Definitions volume of POSIX.1‐2017, <sys_socket.h>
81
83 Portions of this text are reprinted and reproduced in electronic form
84 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
85 table Operating System Interface (POSIX), The Open Group Base Specifi‐
86 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
87 Electrical and Electronics Engineers, Inc and The Open Group. In the
88 event of any discrepancy between this version and the original IEEE and
89 The Open Group Standard, the original IEEE and The Open Group Standard
90 is the referee document. The original Standard can be obtained online
91 at http://www.opengroup.org/unix/online.html .
92
93 Any typographical or formatting errors that appear in this page are
94 most likely to have been introduced during the conversion of the source
95 files to man page format. To report such errors, see https://www.ker‐
96 nel.org/doc/man-pages/reporting_bugs.html .
97
98
99
100IEEE/The Open Group 2017 GETPEERNAME(3P)