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

NAME

6       getsockname - get socket name
7

SYNOPSIS

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

DESCRIPTION

15       getsockname() returns the current address to which the socket sockfd is
16       bound, in the buffer pointed to by addr.  The addrlen  argument  should
17       be initialized to indicate the amount of space (in bytes) pointed to by
18       addr.  On return it contains the actual size of the socket address.
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 to indicate the error.
27

ERRORS

29       EBADF  The argument sockfd is not a valid file 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       ENOTSOCK
41              The file descriptor sockfd does not refer to a socket.
42

CONFORMING TO

44       POSIX.1-2001,  POSIX.1-2008, SVr4, 4.4BSD (getsockname() first appeared
45       in 4.2BSD).
46

NOTES

48       For background on the socklen_t type, see accept(2).
49

SEE ALSO

51       bind(2), socket(2), getifaddrs(3), ip(7), socket(7), unix(7)
52

COLOPHON

54       This page is part of release 5.12 of the Linux  man-pages  project.   A
55       description  of  the project, information about reporting bugs, and the
56       latest    version    of    this    page,    can     be     found     at
57       https://www.kernel.org/doc/man-pages/.
58
59
60
61Linux                             2021-03-22                    GETSOCKNAME(2)
Impressum