TCP/IP Programming Manual
Usage Guidelines
• This call requires the presence of a SERVICES file providing information on the available
services. The format of this file is described in the TCP/IPv6 Configuration and Management
Manual and in the Cluster I/O Protocols Configuration and Management Manual.
• The servent structure is statically declared. Subsequent calls to getservbyport replaces
the existing data in the servent structure.
getsockname, getsockname_nw
The getsockname and getsockname_nw functions get the address and port number to which
a socket is bound.
C Synopsis
#include <socket.h>
#include <in.h>
#include <in6.h> /* for IPv6 use */
#include <netdb.h>
error = getsockname (socket, address_ptr, address_len_ptr);
error = getsockname_nw (socket, address_ptr,
address_len_ptr, tag);
 int error, socket;
 struct sockaddr *address_ptr;
 int *address_len_ptr;
 long tag;
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
error := getsockname (socket, address_ptr, address_len_ptr);
error := getsockname_nw (socket, address_ptr,
address_len_ptr, tag);
 INT(32) error;
 INT(32) socket,
 .EXT address_ptr (sockaddr);
 INT .EXT address_len_ptr;
 INT(32) tag;
error
return value; if the call is successful, a zero is returned. If the call is not successful, —1is returned.
If the call failed, the external variable errno is set as indicated in Errors (page 127).
socket
input value; specifies the socket number for the socket, as returned by the call to socket or
socket_nw.
address_ptr
input and return value; on completion, points to the address and port number to which the
socket is bound.
If the socket is not bound, the address returned contains a port number of 0 and the Internet
address INADDR_ANY.
126 Library Routines










