Since you didn't specify anything, it's listening
on INADDR_ANY, or all the ip addresses on the
machine. This is typically represented as 0.0.0.0.
Had you specified LocalAddr, it could have been
something more specific. It may be more interesting
to check the ip address on the new IO::Socket::INET
object you get after an
accept().
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.
my ($hostaddr_as_a_string)=$socket->sockhost();
print "Local addr is $hostaddr_as_a_string\n";
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 ?"
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 ).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.