2002-08-14 21:03:52 +02:00
|
|
|
/*
|
|
|
|
* 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 <errno.h>
|
2002-08-14 20:44:23 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-14 21:03:52 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <netdb.h>
|
2002-08-14 20:44:23 +02:00
|
|
|
|
|
|
|
#include "hstrerror.h"
|
|
|
|
|
2002-08-14 21:06:39 +02:00
|
|
|
char cvs_id[] = "$Id: fqdn.c,v 1.3 2002-08-14 19:06:39 hjp Exp $";
|
2002-08-14 21:03:52 +02:00
|
|
|
|
2002-08-14 20:44:23 +02:00
|
|
|
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;
|
2002-08-14 21:03:52 +02:00
|
|
|
char hostname[256];
|
2002-08-14 21:06:39 +02:00
|
|
|
char *fake_argv[] = { NULL, hostname, NULL };
|
2002-08-14 20:44:23 +02:00
|
|
|
|
|
|
|
cmnd = argv[0];
|
|
|
|
|
|
|
|
if (argc < 2) {
|
2002-08-14 21:03:52 +02:00
|
|
|
if (gethostname(hostname, sizeof(hostname)) == -1) {
|
|
|
|
fprintf(stderr, "%s: cannot get hostname: %s\n",
|
|
|
|
cmnd, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
argv = fake_argv;
|
|
|
|
argc = 2;
|
2002-08-14 20:44:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|