getsockname() - get socket name
int getsockname (int s, struct sockaddr *name, int *namelen)
The getsockname(2) function returns the current name for the specified socket. 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 call succeeds, it returns 0. If it fails, it returns -1 and sets errno to indicate the error.
The call succeeds unless:
bind(2)
socket(2)