1getsockname(2)                System Calls Manual               getsockname(2)
2
3
4

NAME

6       getsockname - get socket name
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

18       getsockname() returns the current address to which the socket sockfd is
19       bound, in the buffer pointed to by addr.  The addrlen  argument  should
20       be initialized to indicate the amount of space (in bytes) pointed to by
21       addr.  On return it contains the actual size of the socket address.
22
23       The returned address is truncated if the buffer provided is too  small;
24       in  this case, addrlen will return a value greater than was supplied to
25       the call.
26

RETURN VALUE

28       On success, zero is returned.  On error, -1 is returned, and  errno  is
29       set to indicate the error.
30

ERRORS

32       EBADF  The argument sockfd is not a valid file descriptor.
33
34       EFAULT The  addr  argument  points to memory not in a valid part of the
35              process address space.
36
37       EINVAL addrlen is invalid (e.g., is negative).
38
39       ENOBUFS
40              Insufficient resources were available in the system  to  perform
41              the operation.
42
43       ENOTSOCK
44              The file descriptor sockfd does not refer to a socket.
45

STANDARDS

47       POSIX.1-2008.
48

HISTORY

50       POSIX.1-2001, SVr4, 4.4BSD (first appeared in 4.2BSD).
51

SEE ALSO

53       bind(2), socket(2), getifaddrs(3), ip(7), socket(7), unix(7)
54
55
56
57Linux man-pages 6.04              2023-04-03                    getsockname(2)
Impressum