Added fqdn command.

This commit is contained in:
hjp 2002-08-14 18:44:23 +00:00
parent 53bae2019f
commit b9699494bb
2 changed files with 51 additions and 2 deletions

View File

@ -1,8 +1,12 @@
include GNUmakevars include GNUmakevars
include GNUmakerules include GNUmakerules
all: gethostbyname all: gethostbyname fqdn
install: $(BINDIR)/gethostbyname install: \
$(BINDIR)/gethostbyname \
$(BINDIR)/axfr \
$(BINDIR)/fqdn \
clean: clean:
rm -f *.bak *.o core gethostbyname rm -f *.bak *.o core gethostbyname
@ -15,6 +19,14 @@ cfg/%:
gethostbyname: gethostbyname.o hstrerror.o gethostbyname: gethostbyname.o hstrerror.o
fqdn: fqdn.o hstrerror.o
hstrerror.o: cfg/have_hstrerror.h hstrerror.o: cfg/have_hstrerror.h
axfr:
%: %.pl
cp $< $@
chmod +x $@
-include *.d -include *.d

37
dns/fqdn.c Normal file
View File

@ -0,0 +1,37 @@
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include "hstrerror.h"
char *cmnd;
void usage(void) {
fprintf(stderr, "Usage: %s [hostname ...]\n", cmnd);
exit(1);
}
int main(int argc, char **argv) {
int i;
int rc = 0;
cmnd = argv[0];
if (argc < 2) {
usage();
}
for (i = 1; i < argc; i++) {
struct hostent *he = gethostbyname(argv[i]);
if (!he) {
fprintf(stderr, "%s: cannot resolve %s: %s\n",
argv[0], argv[i], hstrerror(h_errno));
rc++;
continue;
}
printf("%s\n", he->h_name);
}
return rc;
}