.\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" %sccs.include.redist.man% .\" .\" @(#)getpeername.2 8.1 (Berkeley) 06/04/93 .\" .Dd .Dt GETPEERNAME 2 .Os BSD 4.2 .Sh NAME .Nm getpeername .Nd get name of connected peer .Sh SYNOPSIS .Ft int .Fn getpeername "int s" "struct sockaddr *name" "int *namelen" .Sh DESCRIPTION .Fn Getpeername returns the name of the peer connected to socket .Fa s . The .Fa namelen parameter should be initialized to indicate the amount of space pointed to by .Fa name . On return it contains the actual size of the name returned (in bytes). The name is truncated if the buffer provided is too small. .Sh DIAGNOSTICS A 0 is returned if the call succeeds, -1 if it fails. .Sh ERRORS The call succeeds unless: .Bl -tag -width ENOTSOCKAA .It Bq Er EBADF The argument .Fa s is not a valid descriptor. .It Bq Er ENOTSOCK The argument .Fa s is a file, not a socket. .It Bq Er ENOTCONN The socket is not connected. .It Bq Er ENOBUFS Insufficient resources were available in the system to perform the operation. .It Bq Er EFAULT The .Fa name parameter points to memory not in a valid part of the process address space. .El .Sh SEE ALSO .Xr accept 2 , .Xr bind 2 , .Xr socket 2 , .Xr getsockname 2 .Sh HISTORY The .Nm function call appeared in .Bx 4.2 .