File: getsockname.2

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