diff --git a/dns/GNUmakefile b/dns/GNUmakefile index 1ad5eb3..83650a7 100644 --- a/dns/GNUmakefile +++ b/dns/GNUmakefile @@ -22,7 +22,7 @@ cfg/%: gethostbyname: gethostbyname.o hstrerror.o -fqdn: fqdn.o hstrerror.o +fqdn: fqdn.pl hstrerror.o: cfg/have_hstrerror.h diff --git a/dns/fqdn.pl b/dns/fqdn.pl new file mode 100755 index 0000000..c4e4235 --- /dev/null +++ b/dns/fqdn.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl +use v5.26; + +sub fqdn { + my ($h) = @_; + + if ($h =~ /\./) { + return $h; + } + open(my $fh, '-|', '/usr/bin/host', $h); + while (<$fh>) { + if (/^(\S+\.\S+) has address/) { + return $1; + } + } + say STDERR "$0: cannot determine FQDN of $h"; + return "$h.invalid"; +} + +if (!@ARGV) { + $ARGV[0] = `/bin/hostname -f`; + chomp($ARGV[0]); +} + +for my $h (@ARGV) { + say fqdn($h); +} diff --git a/dns/gethostbyaddr.c b/dns/gethostbyaddr.c index b646948..6f6891a 100644 --- a/dns/gethostbyaddr.c +++ b/dns/gethostbyaddr.c @@ -2,6 +2,10 @@ #include #include +#include +#include +#include + #include "hstrerror.h" char *cmnd;