Debian Codegraph @

upstream/debian-unstable/man2/getsockname.2

raw
1 .\" Copyright 1983-1991, The Regents of the University of California.
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
5 .\"
6 .TH getsockname 2 2025-10-29 "Linux man-pages 6.18"
7 .SH NAME
8 getsockname \- get socket name
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ,\~ \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/socket.h>
15 .P
16 .BI "int getsockname(int " sockfd ", struct sockaddr *restrict " addr ,
17 .BI " socklen_t *restrict " addrlen );
18 .fi
19 .SH DESCRIPTION
20 .BR getsockname ()
21 returns the current address to which the socket
22 .I sockfd
23 is bound, in the buffer pointed to by
24 .IR addr .
25 The
26 .I addrlen
27 argument should be initialized to indicate
28 the amount of space (in bytes) pointed to by
29 .IR addr .
30 On return it contains the actual size of the socket address.
31 .P
32 The returned address is truncated if the buffer provided is too small;
33 in this case,
34 .I addrlen
35 will return a value greater than was supplied to the call.
36 .SH RETURN VALUE
37 On success, zero is returned.
38 On error, \-1 is returned, and
39 .I errno
40 is set to indicate the error.
41 .SH ERRORS
42 .TP
43 .B EBADF
44 The argument
45 .I sockfd
46 is not a valid file descriptor.
47 .TP
48 .B EFAULT
49 The
50 .I addr
51 argument points to memory not in a valid part of the
52 process address space.
53 .TP
54 .B EINVAL
55 .I addrlen
56 is invalid (e.g., is negative).
57 .TP
58 .B ENOBUFS
59 Insufficient resources were available in the system
60 to perform the operation.
61 .TP
62 .B ENOTSOCK
63 The file descriptor
64 .I sockfd
65 does not refer to a socket.
66 .SH STANDARDS
67 POSIX.1-2024.
68 .SH HISTORY
69 POSIX.1-2001, SVr4, 4.2BSD.
70 .\" SVr4 documents additional ENOMEM
71 .\" and ENOSR error codes.
72 .SH SEE ALSO
73 .BR bind (2),
74 .BR socket (2),
75 .BR getifaddrs (3),
76 .BR ip (7),
77 .BR socket (7),
78 .BR unix (7)