getsockname function returns information about the
address of the socket socket in the locations specified by the
addr and length-ptr arguments. Note that the
length-ptr is a pointer; you should initialize it to be the
allocation size of addr, and on return it contains the actual
size of the address data.
The format of the address data depends on the socket namespace. The
length of the information is usually fixed for a given namespace, so
normally you can know exactly how much space is needed and can provide
that much. The usual practice is to allocate a place for the value
using the proper data type for the socket's namespace, then cast its
struct sockaddr * to pass it to
The return value is
0 on success and
-1 on error. The
errno error conditions are defined for this function:
- The socket argument is not a valid file descriptor.
- The descriptor socket is not a socket.
- There are not enough internal buffers available for the operation.