DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

getsockname(SSC)


getsockname -- get socket address

Synopsis

cc [options] file -lsocket -lnsl
#include <sys/types.h>
#include <sys/socket.h>

int getsockname(int socket, struct sockaddr *name, size_t *namelen);

Description

getsockname returns the current locally bound address, name, for socket s. The namelen parameter should be initialized to indicate the amount of space pointed to by name. On return it contains the actual size of the name returned (in bytes).

If the socket has not been bound to a local name, getsockname sets the value pointed to by namelen to 0, and puts nothing in the struct sockaddr pointed to by name.

Files

/usr/lib/locale/locale/LC_MESSAGES/uxnsl

Return values

0 is returned if the call succeeds; -1 if it fails.

Errors

The call succeeds unless:

EBADF
socket is not a valid descriptor.

ENOTSOCK
socket is a file, not a socket.

EOPNOTSUPP
The operation is not supported for this socket's protocol.

ENOMEM
There was insufficient user memory for the operation to complete.

ENOSR
There were insufficient STREAMS resources available for the operation to complete.

EINVAL
The socket has been shut down.

ENOBUFS
System resources were insufficient to complete the call.

References

bind(SSC), getpeername(SSC), socket(SSC)

RFC 2133

Notices

The type of address structure passed to getsockname depends on the address family. UNIX® domain sockets (address family AF_UNIX) require a struct sockaddr_un structure as defined in sys/un.h; Internet domain IPv4 sockets (address family AF_INET) require a struct sockaddr_in structure as defined in netinet/in.h; Internet domain IPv6 sockets (address family AF_INET6) require a struct sockaddr_in6 structure as defined in netinet/in.h. Other address families may require other structures. Use the structure appropriate to the address family; cast the structure address to a generic struct sockaddr * in the call to getsockname and pass the size of the structure in the namelen argument.

The sockaddr structure has been modified from previous releases to support variable length sockets. The net result of this modification is that the family member has been shortened to 8 bits and a new 8-bit member inserted before it called len. For more information on the new sockaddr structures, see: unix(ADMP) and inet(ADMP).


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005