Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: How to get wildcard addresses using getaddrinfo?

by VinsWorldcom (Parson)
on Aug 21, 2012 at 11:48 UTC ( #988709=note: print w/replies, xml ) Need Help??

in reply to How to get wildcard addresses using getaddrinfo?

For address family independent DNS lookups, I used this as a test for IPv6 support in Perl. This may not be the most elegant way of doing it, but it returns both IPv4 and IPv6 addresses for my local workstation and domain names you enter.

# On Windows without modifying Socket compilation use Socket qw(inet_ntoa unpack_sockaddr_in IPPROTO_TCP AF_INET AF_UNSP +EC); use Socket6; use Socket::GetAddrInfo qw(getaddrinfo getnameinfo); # OR just this with Socket modified - +/2012/08/ipv6-in-perl-on-windows_20.html use Socket 2.005 qw(:addrinfo inet_ntoa inet_ntop unpack_sockaddr_in u +npack_sockaddr_in6 IPPROTO_TCP AF_INET AF_UNSPEC); use Sys::Hostname; if (!@ARGV) { $ARGV[0] = hostname; } my %hints = ( family => AF_UNSPEC, protocol => IPPROTO_TCP ); my ($err, @getaddr) = getaddrinfo($ARGV[0], undef, \%hints); if (defined($getaddr[0])) { for my $addr (@getaddr) { my $address; if ($addr->{family} == AF_INET) { (undef, $address) = unpack_sockaddr_in($addr->{addr}) } else { (undef, $address) = unpack_sockaddr_in6($addr->{addr}) } my $host = inet_ntop($addr->{family}, $address); print "$host\n"; if (0) { # set to 1 to do reverse lookup my ($err, $host, $service) = getnameinfo($addr->{addr}, NI +_NAMEREQD); printf " |_> %s\n", (defined($host)) ? $host : $err } } } else { print "$0: getaddrinfo() failed - error = $err\n" }

And the results (note my local IPv6 addresses obscured with XXXX ...):

VinsWorldcom@C:\Users\VinsWorldcom\tmp> fe80::WWWW:XXXX:YYYY:ZZZZ fe80::WWWW:XXXX:YYYY:ZZZZ fe80::WWWW:XXXX:YYYY:ZZZZ AAAA:BBBB:CCCC:DDDD:WWWW:XXXX:YYYY:ZZZZ fe80::WWWW:XXXX:YYYY:ZZZZ fe80::WWWW:XXXX:YYYY:ZZZZ VinsWorldcom@C:\Users\VinsWorldcom\tmp> 2001:4860:800a::6a

Replies are listed 'Best First'.
Re^2: How to get wildcard addresses using getaddrinfo?
by sushant.ravale (Initiate) on Aug 21, 2012 at 12:32 UTC
    thanks for the reply, getaddrinfo('<wildcard>', 3786, AF_UNSPEC, SOCK_STREAM, 0, AI_PASSIVE); solved the issue, I am getting wild card addresses now.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988709]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-03-21 09:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (265 votes). Check out past polls.