Merge branch 'master' of github.com:hjp/simple

This commit is contained in:
Peter J. Holzer 2022-09-02 21:00:33 +02:00
commit 1efa5739d9
3 changed files with 32 additions and 1 deletions

View File

@ -22,7 +22,7 @@ cfg/%:
gethostbyname: gethostbyname.o hstrerror.o gethostbyname: gethostbyname.o hstrerror.o
fqdn: fqdn.o hstrerror.o fqdn: fqdn.pl
hstrerror.o: cfg/have_hstrerror.h hstrerror.o: cfg/have_hstrerror.h

27
dns/fqdn.pl Executable file
View File

@ -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);
}

View File

@ -2,6 +2,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "hstrerror.h" #include "hstrerror.h"
char *cmnd; char *cmnd;