mirror of https://github.com/sipwise/ngcpcfg.git
For iptables firewall rules it is necessary to translate hostnames, which may be used in config.yml into a list of IPs as returned by "gethostbyname". Change-Id: I149227d5031534d3826a2c91012a599f7c7c4756changes/53/11553/1
parent
c1e3eccaf3
commit
2abadfe9fd
@ -0,0 +1,27 @@
|
||||
[%
|
||||
# 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 -%]
|
||||
Loading…
Reference in new issue