1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\" @(#)getpeername.2 6.5 (Berkeley) 3/10/91
8 .\" Modified Sat Jul 24 16:37:50 1993 by Rik Faith <faith@cs.unc.edu>
9 .\" Modified Thu Jul 30 14:37:50 1993 by Martin Schulze <joey@debian.org>
10 .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer <aeb@cwi.nl>
11 .\" Modified 17 Jul 2002, Michael Kerrisk <mtk.manpages@gmail.com>
12 .\" Added 'socket' to NAME, so that "man -k socket" will show this page.
14 .TH getpeername 2 (date) "Linux man-pages (unreleased)"
16 getpeername \- get name of connected peer socket
19 .RI ( libc ", " \-lc )
22 .B #include <sys/socket.h>
24 .BI "int getpeername(int " sockfd ", struct sockaddr *restrict " addr ,
25 .BI " socklen_t *restrict " addrlen );
29 returns the address of the peer connected to the socket
31 in the buffer pointed to by
35 argument should be initialized to indicate the amount of space pointed to
38 On return it contains the actual size of the name returned (in bytes).
39 The name is truncated if the buffer provided is too small.
41 The returned address is truncated if the buffer provided is too small;
44 will return a value greater than was supplied to the call.
46 On success, zero is returned.
47 On error, \-1 is returned, and
49 is set to indicate the error.
55 is not a valid file descriptor.
60 argument points to memory not in a valid part of the
61 process address space.
65 is invalid (e.g., is negative).
68 Insufficient resources were available in the system
69 to perform the operation.
72 The socket is not connected.
77 does not refer to a socket.
81 POSIX.1-2001, SVr4, 4.4BSD
82 (first appeared in 4.2BSD).
84 For stream sockets, once a
86 has been performed, either socket can call
88 to obtain the address of the peer socket.
89 On the other hand, datagram sockets are connectionless.
92 on a datagram socket merely sets the peer address for outgoing
101 to obtain the peer address that it earlier set for the socket.
102 However, the peer socket is unaware of this information, and calling
104 on the peer socket will return no useful information (unless a
106 call was also executed on the peer).
107 Note also that the receiver of a datagram can obtain
108 the address of the sender when using