1GETPEERNAME(2) Linux Programmer's Manual GETPEERNAME(2)
2
3
4
6 getpeername - get name of connected peer socket
7
9 #include <sys/socket.h>
10
11 int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
12
14 getpeername() returns the address of the peer connected to the socket
15 sockfd, in the buffer pointed to by addr. The addrlen argument should
16 be initialized to indicate the amount of space pointed to by addr. On
17 return it contains the actual size of the name returned (in bytes).
18 The name is truncated if the buffer provided is too small.
19
20 The returned address is truncated if the buffer provided is too small;
21 in this case, addrlen will return a value greater than was supplied to
22 the call.
23
25 On success, zero is returned. On error, -1 is returned, and errno is
26 set appropriately.
27
29 EBADF The argument sockfd is not a valid descriptor.
30
31 EFAULT The addr argument points to memory not in a valid part of the
32 process address space.
33
34 EINVAL addrlen is invalid (e.g., is negative).
35
36 ENOBUFS
37 Insufficient resources were available in the system to perform
38 the operation.
39
40 ENOTCONN
41 The socket is not connected.
42
43 ENOTSOCK
44 The argument sockfd is a file, not a socket.
45
47 SVr4, 4.4BSD (the getpeername() function call first appeared in
48 4.2BSD), POSIX.1-2001.
49
51 The third argument of getpeername() is in reality an int * (and this is
52 what 4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted
53 in the present socklen_t, also used by glibc. See also accept(2).
54
56 accept(2), bind(2), getsockname(2), ip(7), socket(7), unix(7)
57
59 This page is part of release 3.22 of the Linux man-pages project. A
60 description of the project, and information about reporting bugs, can
61 be found at http://www.kernel.org/doc/man-pages/.
62
63
64
65Linux 2008-12-03 GETPEERNAME(2)