GETSOCKNAME

The GETSOCKNAME call returns the address currently bound to a specified socket. If the socket is not currently bound to an address, the call returns with the FAMILY field set, and the rest of the structure set to 0.

Since a socket is not assigned a name until after a successful call to either BIND, CONNECT, or ACCEPT, the GETSOCKNAME call can be used after an implicit bind to discover which port was assigned to the socket.

Example of GETSOCKNAME call

SOC_FUNCTION DC   CL16'GETSOCKNAME'
S            DS   H
NAME         DS   0XL16
FAMILY       DS   H
PORT         DS   H
IP_ADDRESS   DS   F
RESERVED     DS   CL8
ERRNO        DS   F
RETCODE      DS   F
 
             CALL DFHSOKET,(SOC_FUNCTION,S,NAME,ERRNO,RETCODE)

Input parameters

SOC_FUNCTION
A 16-byte character field containing GETSOCKNAME. The field is left-justified and padded on the right with blanks.
S
A halfword binary number set to the descriptor of a local socket whose address is required.

Output parameters

NAME
Specifies the socket address structure returned by the call.
FAMILY
A halfword binary field containing the addressing family. The call always returns the value 2, indicating AF_INET.
PORT
A halfword binary field set to the port number bound to this socket. If the socket is not bound, zero is returned.
IP_ADDRESS
A fullword binary field set to the 32-bit internet address of the local host machine.
RESERVED
Specifies eight bytes of binary zeros. This field is required but not used.
ERRNO
A fullword binary field. If RETCODE is negative, the field contains an error number. See Return codes for information about ERRNO return codes.
RETCODE
A fullword binary field that returns one of the following:
Value
Description
0
Successful call
-1
Check ERRNO for an error code


dfhtn0u.html | Timestamp icon Last updated: Monday, 5 June 2017