home *** CD-ROM | disk | FTP | other *** search
- /*
- * HOSTNAME.c
- *
- * hostname [-finv]
- *
- * List our hostname.
- *
- * -f: list the FQDN, not just the nodename.
- * -i: should be "list IP address". Currently ignored.
- * -n: should be " ". Currently ignored.
- * -v: be verbose.
- *
- * Copyright 1993 by Michael B. Smith. All rights reserved.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "version.h"
- #include "protos.h"
-
- IDENT (".01");
-
- void
- usage (const char *name)
- {
- fprintf (stderr, "usage: %s [-finv]\n", name);
- exit (30);
- }
-
- int
- main (int argc, char **argv)
- {
- char
- *nm = argv [0],
- *nodename,
- *domainname,
- *p;
- int
- i,
- opt_f = 0,
- opt_i = 0,
- opt_n = 0,
- opt_v = 0;
-
- for (i = 1; i < argc; i++) {
- p = argv [i];
- if (*p != '-')
- usage (nm);
- p++;
- switch (*p) {
- case 'f':
- opt_f = 1;
- break;
- case 'i':
- opt_i = 1;
- if (opt_v)
- fprintf (stderr, "option ignored %s\n", p);
- break;
- case 'n':
- opt_n = 1;
- if (opt_v)
- fprintf (stderr, "option ignored %s\n", p);
- break;
- case 'v':
- opt_v = 1;
- break;
- default:
- usage (nm);
- }
- }
-
- nodename = FindConfig (NODENAME);
- if (!nodename) {
- fprintf (stderr, "Can't find NodeName\n");
- exit (30);
- }
-
- if (opt_f) {
- domainname = FindConfig (DOMAINNAME);
- if (!domainname) {
- if (opt_v)
- fprintf (stderr, "domain of .UUCP assumed\n");
-
- domainname = ".UUCP";
- }
-
- p = malloc (strlen (nodename) + strlen (domainname) + 3);
- if (!p) {
- fprintf (stderr, "No memory!\n");
- exit (30);
- }
- strcpy (p, nodename);
- if (*domainname != '.') {
- if (opt_v)
- fprintf (stderr, "added extra period\n");
-
- strcat (p, ".");
- }
-
- strcat (p, domainname);
- nodename = p;
- }
-
- puts (nodename);
-
- if (opt_f)
- free (nodename);
-
- exit (0);
- }
-