#include <sys.socket.h>
#include <netinet.in.h> /* only for AF_INET and AF_INET6 */
#include <iso.h> /* only for AF_ISO */
Kernighan-Ritchie-C:
int getsockname(s, name, namelen);
int s;
int *namelen;
struct sockaddr_in *name; /* only for AF_INET */
struct sockaddr_in6 *name; /* only for AF_INET6 */
struct sockaddr_iso *name; /* only for AF_ISO */
ANSI-C:
int getsockname(int s, struct sockaddr* name, int* namelen);
Description
The getsockname() function returns the current name for socket s in the name parameter.
name points to a memory area. On successful execution of getsockname(), *name contains the name (address) of socket s. Before calling getsockname(), the integer variable to which the namelen parameter points must be supplied with the address length (in bytes). When the function returns, *namelen contains the current size of the returned name in bytes.
Return value
0:
If successful.
-1:
If errors occur. errno is set to indicate the error.
Errors indicated by errno
EBADF
The s parameter is not a valid descriptor.
EFAULT
The length of the area for accepting the address is too small.
EOPNOTSUPP
Socket s is not of type SOCK_STREAM, and the operation is not supported for the socket type of s.
See also
bind(), getpeername(), socket()