The SockGetSockName() call gets the local socket name.
is the socket descriptor.
is a stem variable that is to receive the address of the socket returned.
SockGetSockName() returns the address for socket in the stem variable address. If the socket is not bound to an address, the call returns a null address.
The returned null address is a stem variable with the family field set to AF_INET, the port field set to 0, and the addr field set to 0.0.0.0.
All sockets are explicitly assigned an address after a successful call to SockBind(). Stream sockets are implicitly assigned an address after a successful call to SockConnect() or SockAccept() if SockBind() was not called.
The SockGetSockName() call is often used to identify the port assigned to a socket after the socket has been implicitly bound to a port. For example, an application can call SockConnect() without previously calling SockBind(). In this case, the SockConnect() call completes the binding necessary by assigning a port to the socket.
The value 0 indicates successful execution of the call. The value -1 indicates an error. You can get the specific error code by calling SockSock_Errno() or SockPSock_Errno(). Possible values are:
socket is not a valid socket descriptor.
There is no buffer space available.
Note: SockGetSockName() interfaces with the C function getsockname().