1GETSOCKNAME(2) Linux Programmer's Manual GETSOCKNAME(2)
2
3
4
6 getsockname - get socket name
7
9 #include <sys/socket.h>
10
11 int getsockname(int sockfd, struct sockaddr *restrict addr,
12 socklen_t *restrict addrlen);
13
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
25 On success, zero is returned. On error, -1 is returned, and errno is
26 set to indicate the error.
27
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
44 POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD (getsockname() first appeared
45 in 4.2BSD).
46
48 For background on the socklen_t type, see accept(2).
49
51 bind(2), socket(2), getifaddrs(3), ip(7), socket(7), unix(7)
52
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)