Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
getsockname() z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference SC27-3660-00 |
|
The getsockname() call stores the current name for the socket specified by the s parameter into the structure pointed to by the name parameter. It returns the address to the socket that has been bound. If the socket is not bound to an address, the call returns with the family set and sets the rest of the structure to 0. For example, an inbound socket in the internet domain would cause the name to point to a sockaddr_in structure with the sin_family field set to AF_INET, and all other fields cleared. Stream sockets are not assigned a name until a call is successful: bind(), connect(), or accept(). The getsockname() call is often used to discover the port assigned to a socket after the socket has been implicitly bound to a port. For example, an application can call connect() without previously calling bind(). In this case, the connect() call completes the binding necessary by assigning a port to the socket. This assignment can be detected using a call to getsockname(). For AF_IUCV, namelen must be initialized to indicate the size of the space pointed to by name, and is set to the number of bytes copied into the space before the call returns. For AF_INET, the input value in the contents of namelen is ignored, but set before the call returns.
Return valuesA value of 0 indicates success;
the value -1 indicates an error. Errno identifies the specific
error.
Related callsaccept(), bind(), connect(), getpeername(), socket() |
Copyright IBM Corporation 1990, 2014
|