Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function gets the local name for a socket.

Syntax

int WSPGetSockName(
  SOCKET 
s,
  struct sockaddr FAR* 
name,
  LPINT 
namelen,
  LPINT 
lpErrno 
);

Parameters

s

[in] Descriptor identifying a bound socket.

name

[out] Pointer to a structure used to supply the address (name) of the socket.

namelen

[in, out] Pointer to an integer that, on input, indicates the size of the structure pointed to by name,and on output indicates the size of the returned name.

lpErrno

[out] Pointer to the error code.

Return Value

If no error occurs, this function returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code is available in lpErrno.

Error value Description

WSAENETDOWN

Network subsystem has failed.

WSAEFAULT

Nameor the namelenparameter is not a valid part of the user address space, or the namelenparameter is too small.

WSAEINPROGRESS

Function is invoked when a callback is in progress.

WSAENOTSOCK

Descriptor is not a socket.

WSAEINVAL

Socket has not been bound to an address with WSPBind, or ADDR_ANY is specified in WSPBindbut connection has not yet occurred.

Remarks

This function retrieves the current name for the specified socket descriptor in name. It is used on a bound and/or connected socket specified by the sparameter. The local association is returned. This call is especially useful when a WSPConnectcall has been made without doing a WSPBindfirst; 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, this function will notnecessarily return information about the host address, unless the socket has been connected with WSPConnector 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.

Requirements

Header ws2spi.h
Library Ws2.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also