in reply to My IP address
The programmatic way to discover this is via getsockname(). (Just FYI, getpeername() does the same for the remote end).
IO::Socket provides some nice shortcuts to get just the info you want, rather than the whole struct sockaddr. It also provides niceties that return ip addresses as text strings, rather than a packed format. In your case, IO::Socket::INET::sockhost makes sense:
See IO::Socket::INET for more info.
While I'm at at, a FAQ about getsockname is "Why would anyone need it ? Since I'm doing the bind(), shouldn't I know what I'm listening on ?"my ($hostaddr_as_a_string)=$socket->sockhost(); print "Local addr is $hostaddr_as_a_string\n";
I'm sure there's other answers, but I think the most typical one is that some socket based programs inherit the socket from a parent process that forked. The child, therefore, may not have called the bind itself.
Update: In retrospect, I suppose that it's more common to use getsockname() on a socket returned from accept(). ( From a listening socket on INADDR_ANY ).
|
|---|