1GETPEERNAME(P) POSIX Programmer's Manual GETPEERNAME(P)
2
3
4
6 getpeername - get the name of the peer socket
7
9 #include <sys/socket.h>
10
11 int getpeername(int socket, struct sockaddr *restrict address,
12 socklen_t *restrict address_len);
13
14
16 The getpeername() function shall retrieve the peer address of the spec‐
17 ified socket, store this address in the sockaddr structure pointed to
18 by the address argument, and store the length of this address in the
19 object pointed to by the address_len argument.
20
21 If the actual length of the address is greater than the length of the
22 supplied sockaddr structure, the stored address shall be truncated.
23
24 If the protocol permits connections by unbound clients, and the peer is
25 not bound, then the value stored in the object pointed to by address is
26 unspecified.
27
29 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
30 returned and errno set to indicate the error.
31
33 The getpeername() function shall fail if:
34
35 EBADF The socket argument is not a valid file descriptor.
36
37 EINVAL The socket has been shut down.
38
39 ENOTCONN
40 The socket is not connected or otherwise has not had the peer
41 pre-specified.
42
43 ENOTSOCK
44 The socket argument does not refer to a socket.
45
46 EOPNOTSUPP
47 The operation is not supported for the socket protocol.
48
49
50 The getpeername() function may fail if:
51
52 ENOBUFS
53 Insufficient resources were available in the system to complete
54 the call.
55
56
57 The following sections are informative.
58
60 None.
61
63 None.
64
66 None.
67
69 None.
70
72 accept() , bind() , getsockname() , socket() , the Base Definitions
73 volume of IEEE Std 1003.1-2001, <sys/socket.h>
74
76 Portions of this text are reprinted and reproduced in electronic form
77 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
78 -- Portable Operating System Interface (POSIX), The Open Group Base
79 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
80 Electrical and Electronics Engineers, Inc and The Open Group. In the
81 event of any discrepancy between this version and the original IEEE and
82 The Open Group Standard, the original IEEE and The Open Group Standard
83 is the referee document. The original Standard can be obtained online
84 at http://www.opengroup.org/unix/online.html .
85
86
87
88IEEE/The Open Group 2003 GETPEERNAME(P)