getsockname

This function gets the local address for a socket.

int getsockname (
SOCKET s, 
struct sockaddr *name, 
int *namelen ); 

Parameters

  • s
    [in] Descriptor that identifies a bound socket.
  • name
    [out] Receives the socket address (name).
  • namelen
    [in/out] name buffer size.

Return Values

Zero indicates no error occurred. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

Remarks

The getsockname function retrieves the current name for the specified socket descriptor in name. It is used on the bound or connected socket specified by the s parameter. The local association is returned. This call is especially useful when a connect call has been made without doing a bind first; the getsockname function provides the only way to determine the local association set by the system.

On call, the namelen argument contains the name buffer size, in bytes. On return, the namelen parameter contains the actual name parameter size, in bytes.

The getsockname function does not always return data about the host address when the socket has been bound to an unspecified address, unless the socket has been connected with connect or accept (for example, using ADDR_ANY). A Windows Sockets application must not assume that the address will be specified unless the socket is connected. The address used for the socket is unknown unless the socket is connected when used in a multihomed host. If the socket is using a connectionless protocol, the address may not be available until I/O occurs on the socket.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and later Winsock.h    

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

accept, bind, connect, getpeername, socket, WSAStartup

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.