|HP-UX Reference > G
getsockname(2)HP-UX 11i Version 3: February 2007
getsockname — get socket address
UNIX 03 Only (X/Open Sockets)
int getsockname( int s, struct sockaddr *__restrict addr, socklen_t *__restrict addrlen );
getsockname() returns the local address of the socket indicated by s, where s is a socket descriptor. addr points to a socket address structure in which this address is returned. addrlen points to a variable that should be initialized to indicate the size of the address structure. On return it contains the actual size of the address returned (in bytes). If addr does not point to enough space to contain the whole address of the socket, only the first addrlen bytes of the address are returned.
The x25_host field of the addr struct returns the X.25 addressing information of the local socket s. The x25ifname field of the addr struct contains the name of the local X.25 interface through which the call arrived.
X/Open Sockets Compilation Environment
Upon successful completion, getsockname() returns 0; otherwise, it returns -1 and sets errno to indicate the error.
getsockname() fails if any of the following conditions are encountered:
Not all possible errno values are documented in this manpage due to dependencies from the underlying protocol modules.
Currently, the socklen_t and size_t types are the same size. This is compatible with the UNIX 95 and UNIX 03 profiles. However, in a future release, socklen_t might be a different size. In that case, passing a size_t pointer will evoke compile-time warnings, which must be corrected in order for the application to behave correctly. Applications that use socklen_t now, where appropriate, will avoid such migration problems. On the other hand, applications that need to be portable to the UNIX 95 profile should follow the X/Open specification (see xopen_networking(7)).
Linking binary objects compiled to X/Open Sockets specification and binary objects compiled to HP-UX BSD Sockets specification to the same executable may result in unexpected behavior, including application abnormal termination and unexpected socket errors. See xopen_networking(7) for details and remedy.
Currently, the default behavior is the HP-UX BSD Sockets; however, it might be changed to X/Open Sockets in a future release. At that time, any HP-UX BSD Sockets behavior that is incompatible with X/Open Sockets might be obsoleted. Applications that conform to the X/Open specification now will avoid migration problems (see xopen_networking(7)).
bind(2), socket(2), getpeername(2), thread_safety(5), inet(7F), xopen_networking(7).