Returns the name associated with a socket. The $QIO equivalent is the IO$_SENSEMODE function with the p3 argument. Format #include <types.h> #include <socket.h> int getsockname ( int s, struct sockaddr *name, int *namelen ); (_DECC_V4_SOURCE) int getsockname ( int s, struct sockaddr *name, size_t *namelen ); (not_DECC_V4_SOURCE)
1 – Arguments
s A socket descriptor created with the socket() function and bound to the socket name with the bind() function. name A pointer to the buffer in which getsockname() should return the socket name. namelen A pointer to an integer containing the size of the buffer pointed to by name. On return, the integer indicates the actual size, in bytes, of the name returned.
2 – Description
This function returns the current name for the specified socket descriptor. The name is in a format specific to the address family assigned to the socket (AF_INET, or AF_INET6 with BSD 4.4 when _SOCKADDR_LEN is defined). The bind() function, not the getsockname() function, makes the association of the name to the socket. Related Functions See also bind() and socket().
3 – Return Values
0 Successful completion. -1 Error; errno is set to indicate the error.
4 – Errors
EBADF The descriptor is invalid. EFAULT The name argument is not a valid part of the user address space. ENOBUFS The system has insufficient resources to complete the call. ENOTSOCK The socket descriptor is invalid. EOPNOTSUPP The operation is not supported for this socket's protocol.