1GETPEERNAME(2)             Linux Programmer's Manual            GETPEERNAME(2)
2
3
4

NAME

6       getpeername - get name of connected peer socket
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
12

DESCRIPTION

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

RETURN VALUE

25       On  success,  zero is returned.  On error, -1 is returned, and errno is
26       set appropriately.
27

ERRORS

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

CONFORMING TO

47       SVr4,  4.4BSD  (the  getpeername()  function  call  first  appeared  in
48       4.2BSD), POSIX.1-2001.
49

NOTES

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

SEE ALSO

56       accept(2), bind(2), getsockname(2), ip(7), socket(7), unix(7)
57

COLOPHON

59       This  page  is  part of release 3.25 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)
Impressum