xref: /original-bsd/lib/libc/sys/getpeername.2 (revision c3e32dec)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)getpeername.2	8.1 (Berkeley) 06/04/93
7.\"
8.Dd
9.Dt GETPEERNAME 2
10.Os BSD 4.2
11.Sh NAME
12.Nm getpeername
13.Nd get name of connected peer
14.Sh SYNOPSIS
15.Ft int
16.Fn getpeername "int s" "struct sockaddr *name" "int *namelen"
17.Sh DESCRIPTION
18.Fn Getpeername
19returns the name of the peer connected to
20socket
21.Fa s .
22The
23.Fa namelen
24parameter should be initialized to indicate
25the amount of space pointed to by
26.Fa name .
27On return it contains the actual size of the name
28returned (in bytes).
29The name is truncated if the buffer provided is too small.
30.Sh DIAGNOSTICS
31A 0 is returned if the call succeeds, -1 if it fails.
32.Sh ERRORS
33The call succeeds unless:
34.Bl -tag -width ENOTSOCKAA
35.It Bq Er EBADF
36The argument
37.Fa s
38is not a valid descriptor.
39.It Bq Er ENOTSOCK
40The argument
41.Fa s
42is a file, not a socket.
43.It Bq Er ENOTCONN
44The socket is not connected.
45.It Bq Er ENOBUFS
46Insufficient resources were available in the system
47to perform the operation.
48.It Bq Er EFAULT
49The
50.Fa name
51parameter points to memory not in a valid part of the
52process address space.
53.El
54.Sh SEE ALSO
55.Xr accept 2 ,
56.Xr bind 2 ,
57.Xr socket 2 ,
58.Xr getsockname 2
59.Sh HISTORY
60The
61.Nm
62function call appeared in
63.Bx 4.2 .
64