You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/lib/get_host_by_name

28 lines
724 B

[%
# Return an array of IPs from a given hostname
#
# @param argv.name The hostname to lookup
# @param argv.type The address family to lookup ("AF_INET" for IPv4,
# "AF_INET6" for IPv6, and "" for both)
# @return out The array of ips
-%]
[% out = [] -%]
[% LOAD_PERL => 1 -%]
[% PERL -%]
use Socket qw(:all);
my $err;
my $ipaddr;
my @res;
my @ips;
($err, @res) = getaddrinfo("[% argv.name %]", "", {socktype => SOCK_RAW, family => [% argv.type %]});
while( my $ai = shift @res ) {
($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx_NOSERV);
push(@ips, $ipaddr);
}
$stash->set(out => \@ips);
[% END -%]
[% out = out.sort -%]