You almost certainly don't want to be using
Socket6 for this. Core's
Socket has had
getaddrinfo for quite some time now, and I keep improving it.
Also, your uses of
inet_ntop are suspect. You shouldn't need to use those. This is what
getnameinfo is for.
use Socket qw( getaddrinfo getnameinfo );
my ( $err, @addrs ) = getaddrinfo( $ARGV[0], 0 );
die $err if $err;
my ( $err, $hostname ) = getnameinfo( $addrs[0]->{addr} );
die $err if $err;
If you dislike that error-in-first-result API style, try
Socket::GetAddrInfo::Strict:
use Socket::GetAddrInfo::Strict qw( getaddrinfo, getnameinfo );
my @addrs = getaddrinfo( $ARGV[0], 0 );
my ( $hostname ) = getnameinfo( $addrs[0]->{addr} );
You shouldn't ever need to use
inet_ntop,
inet_pton,
gethostby*, or any of those other legacies. Any time you want to turn something human-readable into something binary, use
getaddrinfo. Any time you want to turn something binary into something human-readable, use
getnameinfo.
Simple. :)
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.