Submitted By: DJ Lucas <dj at linuxfromscratch dot org>
Date: 2004-06-28
Initial Package Version: 5.2.1
Origin: Self
Upstream Status: N/A
Description:  I got lazy and didn't want to build net-tools anymore.  This
patch is kinda wrong, but the final product is correct.  The patch does
exactly what it's name says it does.  Replace coreutils' hostname with almost
exactly the same one included with net-tools.  Only changes from net-tools
are that I removed DECNet --node option, and added the standard coreutils
version blurb (not the right way, but it works).  This patch is intended to
be applied immediately after applying the suppress and uname patches provided
by LFS. You will also need to add hostname to the list of binaries that are
moved from /usr/bin to bin, and manually create the symlinks to domainname,
dnsdomainname, nisdomainname and ypdomainname unless somebody would like to
hack that into the next version of the patch.


diff -Naur coreutils-5.2.1-orig/man/Makefile.in coreutils-5.2.1/man/Makefile.in
--- coreutils-5.2.1-orig/man/Makefile.in	2004-06-28 23:35:26.763176200 -0500
+++ coreutils-5.2.1/man/Makefile.in	2004-06-28 23:36:19.682131296 -0500
@@ -535,7 +535,6 @@
 groups.1:	$(common_dep)	$(srcdir)/groups.x	../src/groups.sh
 head.1:		$(common_dep)	$(srcdir)/head.x	../src/head.c
 hostid.1:	$(common_dep)	$(srcdir)/hostid.x	../src/hostid.c
-hostname.1:	$(common dep)	$(srcdir)/hostname.x	../src/hostname.c
 id.1:		$(common_dep)	$(srcdir)/id.x		../src/id.c
 install.1:	$(common_dep)	$(srcdir)/install.x	../src/install.c
 join.1:		$(common_dep)	$(srcdir)/join.x	../src/join.c
@@ -617,7 +616,7 @@
 check-x-vs-1:
 	PATH=../src$(PATH_SEPARATOR)$$PATH; export PATH;		\
 	t=ls-files.$$$$;						\
-	(cd $(srcdir) && ls -1 *.x) | grep -v 'uptime.x' | grep -v 'kill.x' | sed 's/\.x$$//' | $(ASSORT) > $$t;      \
+	(cd $(srcdir) && ls -1 *.x) | grep -v 'hostname.x' | grep -v 'uptime.x' | grep -v 'kill.x' | sed 's/\.x$$//' | $(ASSORT) > $$t;      \
 	echo $(dist_man_MANS) | tr -s ' ' '\n' | sed 's/\.1$$//'	\
 	  | $(ASSORT) | diff - $$t || { rm $$t; exit 1; };		\
 	rm $$t
diff -Naur coreutils-5.2.1-orig/man/hostname.1 coreutils-5.2.1/man/hostname.1
--- coreutils-5.2.1-orig/man/hostname.1	2004-03-02 16:52:27.000000000 -0600
+++ coreutils-5.2.1/man/hostname.1	2004-06-28 23:36:19.704127952 -0500
@@ -1,41 +1,191 @@
-.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33.
-.TH HOSTNAME "1" "March 2004" "hostname 5.2.1" "User Commands"
+.TH HOSTNAME 1 "28 Jan 1996" "net-tools" "Linux Programmer's Manual"
+
 .SH NAME
-hostname \- set or print the name of the current host system
+hostname \- show or set the system's host name
+.br
+domainname \- show or set the system's NIS/YP domain name
+.br
+dnsdomainname \- show the system's DNS domain name
+.br
+nisdomainname \- show or set system's NIS/YP domain name
+.br
+ypdomainname \- show or set the system's NIS/YP domain name
+
 .SH SYNOPSIS
 .B hostname
-[\fINAME\fR]
-.br
+.RB [ \-v ]
+.RB [ \-a ]
+.RB [ \-\-alias ]
+.RB [ \-d ]
+.RB [ \-\-domain ]
+.RB [ \-f ]
+.RB [ \-\-fqdn ]
+.RB [ \-i ]
+.RB [ \-\-ip-address ]
+.RB [ \-\-long ]
+.RB [ \-s ]
+.RB [ \-\-short ]
+.RB [ \-y ]
+.RB [ \-\-yp ]
+.RB [ \-\-nis ]
+
+.PP
+.B hostname 
+.RB [ \-v ]
+.RB [ \-F\ filename ]
+.RB [ \-\-file\ filename ]
+.RB [ hostname ]
+
+.PP
+.B domainname
+.RB [ \-v ]
+.RB [ \-F\ filename ]
+.RB [ \-\-file\ filename ]
+.RB [ name ]
+
+.PP
 .B hostname
-\fIOPTION\fR
-.SH DESCRIPTION
-.\" Add any additional description here
+.RB [ \-v ]
+.RB [ \-h ]
+.RB [ \-\-help ]
+.RB [ \-V ]
+.RB [ \-\-version ]
+
 .PP
-Print or set the hostname of the current system.
+.B dnsdomainname
+.RB [ \-v ]
+.br
+.B nisdomainname
+.RB [ \-v ]
+.br
+.B ypdomainname
+.RB [ \-v ]
+
+.SH DESCRIPTION
+.B Hostname
+is the program that is used to either set or display
+the current host, domain or node name of the system.  These names are used
+by many of the networking programs to identify the machine. The domain 
+name is also used by NIS/YP.
+
+.SS "GET NAME"
+When called without any arguments, the program displays the current
+names:
+
+.LP
+.B hostname
+will print the name of the system as returned by the
+.BR gethostname (2)
+function.
+
+.LP
+.B "domainname, nisdomainname, ypdomainname"
+will print the name of the system as returned by the
+.BR getdomainname (2)
+function. This is also known as the YP/NIS domain name of the system.
+
+.LP
+.B dnsdomainname
+will print the domain part of the FQDN (Fully Qualified Domain Name). The
+complete FQDN of the system is returned with
+.BR "hostname \-\-fqdn" .
+
+.SS "SET NAME"
+When called with one argument or with the 
+.B \-\-file
+option, the commands set the host name, the NIS/YP domain name or
+the node name. 
+
+.LP
+Note, that only the super-user can change the names. 
+
+.LP
+It is not possible to set the FQDN or the DNS domain name with the 
+.B dnsdomainname 
+command (see 
+.B "THE FQDN"
+below).
+
+.LP
+The host name is usually set once at system startup in
+.I /etc/rc.d/rc.inet1
+or
+.I /etc/init.d/boot
+(normally by reading the contents of a file which contains
+the host name, e.g. 
+.IR /etc/hostname ).
+
+.SS THE FQDN
+You can't change the FQDN (as returned by 
+.BR "hostname \-\-fqdn" ) 
+or the DNS domain name (as returned by
+.BR "dnsdomainname" ) 
+with this command. The FQDN of the system is the name that the
+.BR resolver (3)
+returns for the host name. 
+
+.LP
+Technically: The FQDN is the name
+.BR gethostbyname (2)
+returns for the host name returned by
+.BR gethostname (2).
+The DNS domain name is the part after the first dot.
+.LP
+Therefore it depends on the configuration (usually in 
+.IR /etc/host.conf )
+how you can change it. Usually (if the hosts file is parsed before DNS or 
+NIS) you can change it in 
+.IR /etc/hosts .
+
+
+.SH OPTIONS
 .TP
-\fB\-\-help\fR
-display this help and exit
+.I "\-a, \-\-alias"
+Display the alias name of the host (if used).
 .TP
-\fB\-\-version\fR
-output version information and exit
+.I "\-d, \-\-domain"
+Display the name of the DNS domain. Don't use the command
+.B domainname
+to get the DNS domain name because it will show the NIS domain name and
+not the DNS domain name. Use
+.B dnsdomainname 
+instead.
+.TP
+.I "\-F, \-\-file filename"
+Read the host name from the specified file. Comments (lines starting with
+a `#') are ignored.
+.TP
+.I "\-f, \-\-fqdn, \-\-long"
+Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a
+short host name and the DNS domain name. Unless you are using bind or NIS
+for host lookups you can change the FQDN and the DNS domain name (which is
+part of the FQDN) in the \fI/etc/hosts\fR file.
+.TP
+.I "\-h, \-\-help"
+Print a usage message and exit.
+.TP
+.I "\-i, \-\-ip-address"
+Display the IP address(es) of the host.
+.TP
+.I "\-s, \-\-short"
+Display the short host name. This is the host name cut at the first dot.
+.TP
+.I "\-V, \-\-version"
+Print version information on standard output and exit successfully.
+.TP
+.I "\-v, \-\-verbose"
+Be verbose and tell what's going on.
+.TP
+.I "\-y, \-\-yp, \-\-nis"
+Display the NIS domain name. If a parameter is given (or 
+.B \-\-file name
+) then root can also set a new NIS domain.
+.SH FILES
+.B /etc/hosts
 .SH AUTHOR
-Written by Jim Meyering.
-.SH "REPORTING BUGS"
-Report bugs to <bug-coreutils@gnu.org>.
-.SH COPYRIGHT
-Copyright \(co 2004 Free Software Foundation, Inc.
-.br
-This is free software; see the source for copying conditions.  There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-.SH "SEE ALSO"
-The full documentation for
-.B hostname
-is maintained as a Texinfo manual.  If the
-.B info
-and
-.B hostname
-programs are properly installed at your site, the command
-.IP
-.B info coreutils hostname
-.PP
-should give you access to the complete manual.
+Peter Tobias, <tobias@et-inf.fho-emden.de>
+.br
+Bernd Eckenfels, <net-tools@lina.inka.de> (NIS and manpage).
+.br
+Steve Whitehouse, <SteveW@ACM.org> (DECnet support and manpage).
+
diff -Naur coreutils-5.2.1-orig/src/Makefile.in coreutils-5.2.1/src/Makefile.in
--- coreutils-5.2.1-orig/src/Makefile.in	2004-06-28 23:35:26.800170576 -0500
+++ coreutils-5.2.1/src/Makefile.in	2004-06-28 23:36:19.706127648 -0500
@@ -617,7 +617,7 @@
 @AMDEP_TRUE@	./$(DEPDIR)/factor.Po ./$(DEPDIR)/false.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/fmt.Po ./$(DEPDIR)/fold.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/head.Po ./$(DEPDIR)/hostid.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/hostname.Po ./$(DEPDIR)/id.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/id.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/install.Po ./$(DEPDIR)/join.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/lbracket.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/link.Po ./$(DEPDIR)/ln.Po \
@@ -1318,7 +1318,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fold.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/head.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hostid.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hostname.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/id.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/install.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/join.Po@am__quote@
diff -Naur coreutils-5.2.1-orig/src/hostname.c coreutils-5.2.1/src/hostname.c
--- coreutils-5.2.1-orig/src/hostname.c	2004-01-21 16:27:02.000000000 -0600
+++ coreutils-5.2.1/src/hostname.c	2004-06-28 23:36:19.728124304 -0500
@@ -15,113 +15,366 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-/* Written by Jim Meyering.  */
+/* Original coreutils hostname completely removed.  This utility taken
+   directly from net-tools-1.60. */
 
-#include <config.h>
-#include <stdio.h>
-#include <sys/types.h>
+/*
+ * hostname   This file contains an implementation of the command
+ *              that maintains the hostname and the domainname. It
+ *              is also used to show the FQDN and the IP-Addresses.
+ *
+ * Usage:       hostname [-d|-f|-s|-a|-i|-y|-n]
+ *              hostname [-h|-V]
+ *              hostname {name|-F file}
+ *              dnsdmoainname
+ *              nisdomainname {name|-F file}
+ *
+ * Version:     hostname 1.96 (1996-02-18)
+ *
+ * Author:      Peter Tobias <tobias@et-inf.fho-emden.de>
+ *
+ * Changes:
+ *      {1.90}  Peter Tobias :          Added -a and -i options.
+ *      {1.91}  Bernd Eckenfels :       -v,-V rewritten, long_opts
+ *                                      (major rewrite), usage.
+ *960120 {1.95} Bernd Eckenfels :       -y/nisdomainname - support for get/
+ *                                      setdomainname added
+ *960218 {1.96} Bernd Eckenfels :       netinet/in.h added
+ *980629 {1.97} Arnaldo Carvalho de Melo : gettext instead of catgets for i18n
+ *20000213 {1.99} Arnaldo Carvalho de Melo : fixed some i18n strings
+ *20010404 {1.100} Arnaldo Carvalho de Melo: use setlocale
+ *20040608 {1.101} DJ Lucas: removed DECNet options and placed in coreutils
+ *
+ *              This program is free software; you can redistribute it
+ *              and/or  modify it under  the terms of  the GNU General
+ *              Public  License as  published  by  the  Free  Software
+ *              Foundation;  either  version 2 of the License, or  (at
+ *              your option) any later version.
+ */
+
+#define RELEASE "hostname (coreutils) 5.2.1 \n\
+Written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim \
+Meyering. \n\nCopyright (C) 2004 Free Software Foundation, Inc. \n\
+This is free software; see the source for copying conditions.  There is NO \n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
 
-#include "system.h"
-#include "long-options.h"
-#include "error.h"
 
-/* The official name of this program (e.g., no `g' prefix).  */
-#define PROGRAM_NAME "hostname"
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <string.h>
+#include <netdb.h>
+#include <errno.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "config.h"
+
+/* Dummy replacement for libintl.h */
+                                                                                
+#if I18N
+#include <locale.h>
+#undef __OPTIMIZE__
+#include <libintl.h>
+#define _(String) gettext((String))
+#define N_(String) (String)
+#else
+#define _(String) (String)
+#define N_(String) (String)
+#endif
 
-#define AUTHORS "Jim Meyering"
+/* End libintl.h */
 
-#if !defined(HAVE_SETHOSTNAME) && defined(HAVE_SYSINFO) && \
-     defined (HAVE_SYS_SYSTEMINFO_H) && defined(HAVE_LIMITS_H)
-# include <sys/systeminfo.h>
+char *Release = RELEASE, *Version = "hostname 1.101 courtesy of net-tools-1.60 \n";
+                                                                                
+static char *program_name;
+static int opt_v;
+                                                                                
+static void sethname(char *);
+static void setdname(char *);
+static void showhname(char *, int);
+static void usage(void);
+static void version(void);
+static void setfilename(char *, int);
+                                                                                
+#define SETHOST         1
+#define SETDOMAIN       2
+#define SETNODE         3
 
-int
-sethostname (name, namelen)
-     char *name;
-     int namelen;
+static void sethname(char *hname)
 {
-  /* Using sysinfo() is the SVR4 mechanism to set a hostname. */
-  int result;
-
-  result = sysinfo (SI_SET_HOSTNAME, name, namelen);
-
-  return (result == -1 ? result : 0);
+    if (opt_v)
+        fprintf(stderr, _("Setting hostname to `%s'\n"),
+                hname);
+    if (sethostname(hname, strlen(hname))) {
+        switch (errno) {
+        case EPERM:
+            fprintf(stderr, _("%s: you must be root to change the host name\n"), program_name);
+            break;
+        case EINVAL:
+            fprintf(stderr, _("%s: name too long\n"), program_name);
+            break;
+        default:
+        }
+        exit(1);
+    };
 }
 
-# define HAVE_SETHOSTNAME 1  /* Now we have it... */
-#endif
-
-char *xgethostname ();
-
-/* The name this program was run with. */
-char *program_name;
+static void setdname(char *dname)
+{
+    if (opt_v)
+        fprintf(stderr, _("Setting domainname to `%s'\n"),
+                dname);
+    if (setdomainname(dname, strlen(dname))) {
+        switch (errno) {
+        case EPERM:
+            fprintf(stderr, _("%s: you must be root to change the domain name\n"), program_name);
+            break;
+        case EINVAL:
+            fprintf(stderr, _("%s: name too long\n"), program_name);
+            break;
+        default:
+        }
+        exit(1);
+    };
+}
 
-void
-usage (int status)
+static void showhname(char *hname, int c)
 {
-  if (status != EXIT_SUCCESS)
-    fprintf (stderr, _("Try `%s --help' for more information.\n"),
-	     program_name);
-  else
-    {
-      printf (_("\
-Usage: %s [NAME]\n\
-  or:  %s OPTION\n\
-Print or set the hostname of the current system.\n\
-\n\
-"),
-             program_name, program_name);
-      fputs (HELP_OPTION_DESCRIPTION, stdout);
-      fputs (VERSION_OPTION_DESCRIPTION, stdout);
-      printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
+    struct hostent *hp;
+    register char *p, **alias;
+    struct in_addr **ip;
+                                                                                
+    if (opt_v)
+        fprintf(stderr, _("Resolving `%s' ...\n"), hname);
+    if (!(hp = gethostbyname(hname))) {
+        herror(program_name);
+        exit(1);
+    }
+    if (opt_v) {
+        fprintf(stderr, _("Result: h_name=`%s'\n"),
+                hp->h_name);
+                                                                                
+        alias = hp->h_aliases;
+        while (alias[0])
+            fprintf(stderr, _("Result: h_aliases=`%s'\n"),
+                    *alias++);
+                                                                                
+        ip = (struct in_addr **) hp->h_addr_list;
+        while (ip[0])
+            fprintf(stderr, _("Result: h_addr_list=`%s'\n"),
+                    inet_ntoa(**ip++));
+    }
+    if (!(p = strchr(hp->h_name, '.')) && (c == 'd'))
+        return;
+                                                                                
+    switch (c) {
+    case 'a':
+        while (hp->h_aliases[0])
+            printf("%s ", *hp->h_aliases++);
+        printf("\n");
+        break;
+    case 'i':
+        while (hp->h_addr_list[0])
+            printf("%s ", inet_ntoa(*(struct in_addr *) *hp->h_addr_list++));
+        printf("\n");
+        break;
+    case 'd':
+        printf("%s\n", ++p);
+        break;
+    case 'f':
+        printf("%s\n", hp->h_name);
+        break;
+    case 's':
+        if (p != NULL)
+            *p = '\0';
+        printf("%s\n", hp->h_name);
+        break;
+    default:
     }
-  exit (status);
 }
 
-int
-main (int argc, char **argv)
+static void setfilename(char *name, int what)
 {
-  char *hostname;
-
-  initialize_main (&argc, &argv);
-  program_name = argv[0];
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+    register FILE *fd;
+    register char *p;
+    char fline[MAXHOSTNAMELEN];
+                                                                                
+    if ((fd = fopen(name, "r")) != NULL) {
+        while (fgets(fline, sizeof(fline), fd) != NULL) {
+            if ((p = index(fline, '\n')) != NULL)
+                *p = '\0';
+            if (opt_v)
+                fprintf(stderr, ">> %s\n", fline);
+            if (fline[0] == '#')
+                continue;
+            switch(what) {
+            case SETHOST:
+                sethname(fline);
+                break;
+            case SETDOMAIN:
+                setdname(fline);
+                break;
+            }
+        }
+        (void) fclose(fd);
+    } else {
+        fprintf(stderr, _("%s: can't open `%s'\n"),
+                program_name, name);
+        exit(1);
+    }
+}
 
-  atexit (close_stdout);
+static void version(void)
+{
+    fprintf(stderr, "%s\n%s\n", Release, Version);
+    exit(5); /* E_VERSION */
+}
 
-  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
-		      usage, AUTHORS, (char const *) NULL);
+static void usage(void)
+{
+    fprintf(stderr, _("Usage:\n"));
+    fprintf(stderr, _("       hostname HOSTNAME[.DOMAINNAME]        sets hostname or FQDN\n"));
+    fprintf(stderr, _("       hostname [-v] [-d|-f|-s|-a|-i|-y|-n]  display formatted name\n"));
+    fprintf(stderr, _("       hostname -V|--version|-h|--help       print info and exit\n\n"));
+    fprintf(stderr, _("       -s, --short           short host name\n"));
+    fprintf(stderr, _("       -a, --alias           alias names\n"));
+    fprintf(stderr, _("       -i, --ip-address      addresses for the hostname\n"));
+    fprintf(stderr, _("       -f, --fqdn, --long    long host name (FQDN)\n"));
+    fprintf(stderr, _("       -d, --domain          DNS domain name\n"));
+    fprintf(stderr, _("       -y, --yp, --nis       NIS/YP domainname\n"));
+    fprintf(stderr, _("       -F, --file            read hostname or NIS domainname from given file\n\n"));
+    fprintf(stderr, _(
+"   This command can read or set the hostname or the NIS domainname. You can\n"
+"   also read the DNS domain or the FQDN (fully qualified domain name).\n"
+"   Unless you are using bind or NIS for host lookups you can change the\n"
+"   FQDN (Fully Qualified Domain Name) and the DNS domain name (which is\n"
+"   part of the FQDN) in the /etc/hosts file.\n"));
+                                                                                
+    exit(4); /* E_USAGE */
+}
 
-#ifdef HAVE_SETHOSTNAME
-  if (argc == 2)
+int main(int argc, char **argv)
+{
+    int c;
+    char type = '\0';
+    int option_index = 0;
+    int what = 0;
+    char myname[MAXHOSTNAMELEN + 1] =
+    {0};
+    char *file = NULL;
+                                                                                
+    static const struct option long_options[] =
     {
-      int err;
-
-      /* Set hostname to argv[1].  */
-      err = sethostname (argv[1], strlen (argv[1]));
-      if (err != 0)
-	error (EXIT_FAILURE, errno, _("cannot set hostname to `%s'"), argv[1]);
-      exit (EXIT_SUCCESS);
-    }
-#else
-  if (argc == 2)
-    error (EXIT_FAILURE, 0,
-	   _("cannot set hostname; this system lacks the functionality"));
+        {"domain", no_argument, 0, 'd'},
+        {"file", required_argument, 0, 'F'},
+        {"fqdn", no_argument, 0, 'f'},
+        {"help", no_argument, 0, 'h'},
+        {"long", no_argument, 0, 'f'},
+        {"short", no_argument, 0, 's'},
+        {"version", no_argument, 0, 'V'},
+        {"verbose", no_argument, 0, 'v'},
+        {"alias", no_argument, 0, 'a'},
+        {"ip-address", no_argument, 0, 'i'},
+        {"nis", no_argument, 0, 'y'},
+        {"yp", no_argument, 0, 'y'},
+#if HAVE_AFDECnet
+        {"node", no_argument, 0, 'n'},
+#endif /* HAVE_AFDECnet */
+        {0, 0, 0, 0}
+    };
+#if I18N
+    setlocale (LC_ALL, "");
+    bindtextdomain("net-tools", "/usr/share/locale");
+    textdomain("net-tools");
 #endif
-
-  if (argc <= 1)
-    {
-      hostname = xgethostname ();
-      if (hostname == NULL)
-	error (EXIT_FAILURE, errno, _("cannot determine hostname"));
-      printf ("%s\n", hostname);
+    program_name = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
+                                                                                
+    if (!strcmp(program_name, "ypdomainname") ||
+        !strcmp(program_name, "domainname") ||
+        !strcmp(program_name, "nisdomainname"))
+        what = 3;
+    if (!strcmp(program_name, "dnsdomainname"))
+        what = 2;
+#if HAVE_AFDECnet
+    if (!strcmp(program_name, "nodename"))
+        what = 4;
+#endif /* HAVE_AFDECnet */
+                                                                                
+    while ((c = getopt_long(argc, argv, "adfF:h?isVvyn", long_options, &option_index)) != EOF)
+        switch (c) {
+        case 'd':
+            what = 2;
+            break;
+        case 'a':
+        case 'f':
+        case 'i':
+        case 's':
+            what = 1;
+            type = c;
+            break;
+        case 'y':
+            what = 3;
+            break;
+        case 'F':
+            file = optarg;
+            break;
+        case 'v':
+            opt_v++;
+            break;
+        case 'V':
+            version();
+        case '?':
+        case 'h':
+        default:
+            usage();
+                                                                                
+        };
+                                                                                
+                                                                                
+    switch (what) {
+    case 2:
+        if (file || (optind < argc)) {
+            fprintf(stderr, _("%s: You can't change the DNS domain name with this command\n"), program_name);
+            fprintf(stderr, _("\nUnless you are using bind or NIS for host lookups you can change the DNS\n"));
+            fprintf(stderr, _("domain name (which is part of the FQDN) in the /etc/hosts file.\n"));
+            exit(1);
+        }
+        type = 'd';
+        /* NOBREAK */
+    case 0:
+        if (file) {
+            setfilename(file, SETHOST);
+            break;
+        }
+        if (optind < argc) {
+            sethname(argv[optind]);
+            break;
+        }
+    case 1:
+        gethostname(myname, sizeof(myname));
+        if (opt_v)
+            fprintf(stderr, _("gethostname()=`%s'\n"), myname);
+        if (!type)
+            printf("%s\n", myname);
+        else
+            showhname(myname, type);
+        break;
+    case 3:
+        if (file) {
+            setfilename(file, SETDOMAIN);
+            break;
+        }
+        if (optind < argc) {
+            setdname(argv[optind]);
+            break;
+        }
+        getdomainname(myname, sizeof(myname));
+        if (opt_v)
+            fprintf(stderr, _("getdomainname()=`%s'\n"), myname);
+        printf("%s\n", myname);
+        break;
     }
-  else
-    {
-      error (0, 0, _("too many arguments"));
-      usage (EXIT_FAILURE);
-    }
-
-  exit (EXIT_SUCCESS);
+    exit(0);
 }
+
