getsockname
SOCKET
This function returns the packed sockaddr address of this end of the
SOCKET
connection.
(And why wouldn't you know your own address already? Because you might
have bound an address containing wildcards to the generic socket
before doing an
accept
. Or because you
might have been passed a
socket by your parent process - for example,
inetd
.)
use Socket;
$mysockaddr = getsockname(SOCK);
($port, $myaddr) = unpack_sockaddr_in($mysockaddr);