The WSPGetSockName function gets the local name for a socket.
int WSPGetSockName (
SOCKET s,
struct sockaddr FAR * name,
LPINT namelen,
LPINT lpErrno
);
WSPGetSockName retrieves the current name for the specified socket descriptor in name. It is used on a bound and/or connected socket specified by the s parameter. The local association is returned. This call is especially useful when a WSPConnect call has been made without doing a WSPBind first; as this call provides the only means by which the local association that has been set by the service provider can be determined.
If a socket was bound to an unspecified address (for example, ADDR_ANY), indicating that any of the host's addresses within the specified address family should be used for the socket, WSPGetSockName will not necessarily return information about the host address, unless the socket has been connected with WSPConnect or WSPAccept. The Windows Sockets SPI client must not assume that an address will be specified unless the socket is connected. This is because for a multihomed host the address that will be used for the socket is unknown until the socket is connected.
If no error occurs, WSPGetSockName returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code is available in lpErrno.
WSAENETDOWN | The network subsystem has failed. |
WSAEFAULT | The name or the namelen argument is not a valid part of the user address space, or the namelen argument is too small. |
WSAEINPROGRESS | The function is invoked when a callback is in progress. |
WSAENOTSOCK | The descriptor is not a socket. |
WSAEINVAL | The socket has not been bound to an address with WSPBind, or ADDR_ANY is specified in WSPBind but connection has not yet occurs. |
Windows NT: Yes
Windows: Yes
Windows CE: Unsupported.
Header: Declared in ws2spi.h.
WSPBind, WSPSocket, WSPGetPeerName