February 2012
Intermediate to advanced
1184 pages
37h 17m
English
getsockname SOCKETThis function returns the packed socket address of this end of
the SOCKET connection. (And why wouldn’t you
know your own address already? Maybe because you bound an address
containing wildcards to the server socket before doing an accept, and now you need to know what
interface someone used to connect to you. Or you were passed a socket by
your parent process—inetd, for example.)
use Socket; # assume thatSOCKis a connected socket $mysockaddr = getsockname(SOCK); ($port, $myaddr) = sockaddr_in($mysockaddr); $myname = gethostbyaddr($myaddr, AF_INET); printf "I am %s [%vd]\n", $myname, $myaddr;
Read now
Unlock full access