From 6ab44ef49916f9eb88bcda1c831e2d859f665a15 Mon Sep 17 00:00:00 2001 From: hjp Date: Wed, 14 Aug 2002 19:03:52 +0000 Subject: [PATCH] Print system's FQDN if no hostname is given. --- dns/fqdn.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/dns/fqdn.c b/dns/fqdn.c index c12494b..6e590d2 100644 --- a/dns/fqdn.c +++ b/dns/fqdn.c @@ -1,9 +1,24 @@ -#include +/* + * fqdn - print fully qualified domain name(s) + * + * resolve all host names given on the comman line and print their + * fully qualified canonical names. + * + * If no argument is given, print the system's FQDN. + */ + +#include #include #include +#include + +#include +#include #include "hstrerror.h" +char cvs_id[] = "$Id: fqdn.c,v 1.2 2002-08-14 19:03:52 hjp Exp $"; + char *cmnd; void usage(void) { @@ -14,11 +29,19 @@ void usage(void) { int main(int argc, char **argv) { int i; int rc = 0; + char hostname[256]; + char *fake_argv[] = { argv[0], hostname, NULL }; cmnd = argv[0]; if (argc < 2) { - usage(); + if (gethostname(hostname, sizeof(hostname)) == -1) { + fprintf(stderr, "%s: cannot get hostname: %s\n", + cmnd, strerror(errno)); + exit(1); + } + argv = fake_argv; + argc = 2; } for (i = 1; i < argc; i++) {