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
20
22 The getpeername() function shall retrieve the peer address of the spec‐
23 ified socket, store this address in the sockaddr structure pointed to
24 by the address argument, and store the length of this address in the
25 object pointed to by the address_len argument.
26
27 If the actual length of the address is greater than the length of the
28 supplied sockaddr structure, the stored address shall be truncated.
29
30 If the protocol permits connections by unbound clients, and the peer is
31 not bound, then the value stored in the object pointed to by address is
32 unspecified.
33
35 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
36 returned and errno set to indicate the error.
37
39 The getpeername() function shall fail if:
40
41 EBADF The socket argument is not a valid file descriptor.
42
43 EINVAL The socket has been shut down.
44
45 ENOTCONN
46 The socket is not connected or otherwise has not had the peer
47 pre-specified.
48
49 ENOTSOCK
50 The socket argument does not refer to a socket.
51
52 EOPNOTSUPP
53 The operation is not supported for the socket protocol.
54
55
56 The getpeername() function may fail if:
57
58 ENOBUFS
59 Insufficient resources were available in the system to complete
60 the call.
61
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(), the Base Definitions volume
79 of IEEE Std 1003.1-2001, <sys/socket.h>
80
82 Portions of this text are reprinted and reproduced in electronic form
83 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
84 -- Portable Operating System Interface (POSIX), The Open Group Base
85 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
86 Electrical and Electronics Engineers, Inc and The Open Group. In the
87 event of any discrepancy between this version and the original IEEE and
88 The Open Group Standard, the original IEEE and The Open Group Standard
89 is the referee document. The original Standard can be obtained online
90 at http://www.opengroup.org/unix/online.html .
91
92
93
94IEEE/The Open Group 2003 GETPEERNAME(3P)