ADC Home > Reference Library > Reference > Mac OS X > Mac OS X Man Pages

 

This document is a Mac OS X manual page. Manual pages are a command-line technology for providing documentation. You can view these manual pages locally using the man(1) command. These manual pages come from many different sources, and thus, have a variety of writing styles.

This manual page is associated with the Mac OS X developer tools. The software or headers described may not be present on your Mac OS X installation until you install the developer tools package. This package is available on your Mac OS X installation DVD, and the latest versions can be downloaded from developer.apple.com.

For more information about the manual page format, see the manual page for manpages(5).



GETSOCKNAME(2)              BSD System Calls Manual             GETSOCKNAME(2)

NAME
     getsockname -- get socket name

SYNOPSIS
     #include <sys/socket.h>

     int
     getsockname(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len);

DESCRIPTION
     Getsockname() returns the current address for the specified socket.  The address_len parameter should
     be initialized to indicate the amount of space pointed to by address.  On return it contains the actual
     size of the name returned (in bytes).

RETURN VALUES
     The getsockname() function returns the value 0 if successful; otherwise the value -1 is returned and
     the global variable errno is set to indicate the error.

ERRORS
     The getsockname() system call will succeed unless:

     [EBADF]            The argument socket is not a valid file descriptor.

     [EFAULT]           The address parameter points to memory not in a valid part of the process address
                        space.

     [EINVAL]           socket has been shut down.

     [ENOBUFS]          Insufficient resources were available in the system to perform the operation.

     [ENOTSOCK]         The argument socket is not a socket (e.g., a plain file).

     [EOPNOTSUPP]       getsockname() is not supported for the protocol in use by socket.

SEE ALSO
     bind(2), socket(2)

BUGS
     Names bound to sockets in the UNIX domain are inaccessible; getsockname() returns a zero-length name.

HISTORY
     The getsockname() call appeared in 4.2BSD.

4.2 Berkeley Distribution        June 4, 1993        4.2 Berkeley Distribution

Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.