mirror of
git://git.proxmox.com/git/pve-common.git
synced 2025-01-11 13:17:36 +03:00
Add utility subroutine to get the fully qualified domain name of a host
This commit is contained in:
parent
7fdae31200
commit
d3c8f0c182
@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
use POSIX qw(EINTR EEXIST EOPNOTSUPP);
|
||||
use IO::Socket::IP;
|
||||
use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED);
|
||||
use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED AI_CANONNAME SOCK_DGRAM);
|
||||
use IO::Select;
|
||||
use File::Basename;
|
||||
use File::Path qw(make_path);
|
||||
@ -1197,6 +1197,24 @@ sub get_host_address_family {
|
||||
return $res[0]->{family};
|
||||
}
|
||||
|
||||
# get the fully qualified domain name of a host
|
||||
# same logic as hostname(1): The FQDN is the name getaddrinfo(3) returns,
|
||||
# given a nodename as a parameter
|
||||
sub get_fqdn {
|
||||
my ($nodename) = @_;
|
||||
|
||||
my $hints = {
|
||||
flags => AI_CANONNAME,
|
||||
socktype => SOCK_DGRAM
|
||||
};
|
||||
|
||||
my ($err, @addrs) = Socket::getaddrinfo($nodename, undef, $hints);
|
||||
|
||||
die "getaddrinfo: $err" if $err;
|
||||
|
||||
return $addrs[0]->{canonname};
|
||||
}
|
||||
|
||||
# Parses any sane kind of host, or host+port pair:
|
||||
# The port is always optional and thus may be undef.
|
||||
sub parse_host_and_port {
|
||||
|
Loading…
Reference in New Issue
Block a user