--- old/usr/src/cmd/hostname/Makefile	2016-04-21 02:41:40.248434307 +0100
+++ new/usr/src/cmd/hostname/Makefile	2016-04-21 02:41:40.253779485 +0100
@@ -22,7 +22,7 @@
 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-# ident	"%Z%%M%	%I%	%E% SMI"
+# Copyright 2016 RackTop Systems.
 #
 
 PROG= hostname
@@ -31,6 +31,8 @@
 
 CFLAGS += $(CCVERBOSE)
 
+LDLIBS += -lnsl
+
 .KEEP_STATE:
 
 all: $(PROG) 
--- old/usr/src/cmd/hostname/hostname.c	2016-04-21 02:41:40.387171827 +0100
+++ new/usr/src/cmd/hostname/hostname.c	2016-04-21 02:41:40.391940930 +0100
@@ -32,11 +32,12 @@
 /*
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2016 RackTop Systems.
  */
 
 /* Portions Copyright 2007 Jeremy Teo */
 /* Portions Copyright 2006 Stephen P. Potter */
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
 
 #include <unistd.h>
 #include <stdio.h>
@@ -47,6 +48,9 @@
 #include <errno.h>
 #include <netdb.h>
 
+extern int getdomainname(char *name, int namelen);
+extern int setdomainname(char *domain, int len);
+
 #ifndef	TEXT_DOMAIN		/* should be defined by cc -D */
 #define	TEXT_DOMAIN "SYS_TEST"	/* use this only if it wasn't */
 #endif
@@ -56,18 +60,16 @@
 static void
 usage(void)
 {
-	(void) fprintf(stderr, gettext("usage: %s [system_name]\n"),
-		basename(progname));
+	(void) fprintf(stderr, gettext("usage: %s [-d|-f] [hostname|domain]\n"),
+	    basename(progname));
 	exit(1);
 }
 
 int
 main(int argc, char *argv[])
 {
-	char	*nodename = NULL;
-	char    c_hostname[MAXHOSTNAMELEN];
-	int	optlet;
-	char	*optstring = "?";
+	int	optlet, dflag = 0, fflag = 0;
+	char	*optstring = "df?";
 
 	(void) setlocale(LC_ALL, "");
 	(void) textdomain(TEXT_DOMAIN);
@@ -77,38 +79,76 @@
 	opterr = 0;
 	while ((optlet = getopt(argc, argv, optstring)) != -1) {
 		switch (optlet) {
+		case 'd':
+			dflag++;
+			break;
+		case 'f':
+			fflag++;
+			break;
 		case '?':
 			usage();
 		}
 	}
 
+	if (dflag && fflag)
+		usage();
+
 	/*
-	 * if called with no options, just print out the hostname/nodename
+	 * if called with no options, just print out the hostname/domain
 	 */
 	if (argc <= optind) {
+		char c_hostname[MAXHOSTNAMELEN];
 		if (gethostname(c_hostname, sizeof (c_hostname)) < 0) {
 			(void) fprintf(stderr,
 			    gettext("%s: unable to obtain hostname\n"),
 			    basename(progname));
 			exit(1);
+		}
+		if (dflag || fflag) {
+			char c_domain[MAXHOSTNAMELEN];
+			if (getdomainname(c_domain, sizeof (c_domain)) < 0) {
+				(void) fprintf(stderr,
+				    gettext("%s: unable to obtain domain\n"),
+				    basename(progname));
+				exit(1);
+			}
+			/* Might not actually get a domain back */
+			if (fflag && *c_domain)
+				(void) fprintf(stdout, "%s.%s\n",
+				    c_hostname, c_domain);
+			else
+				(void) fprintf(stdout, "%s\n",
+				    dflag ? c_domain : c_hostname);
 		} else {
 			(void) fprintf(stdout, "%s\n", c_hostname);
 		}
 	} else {
 		/*
 		 * if called with an argument,
-		 * we have to try to set the new hostname/nodename
+		 * we have to try to set the new hostname/domain
 		 */
 		if (argc > optind + 1)
 			usage();	/* too many arguments */
-
-		nodename = argv[optind];
-		if (sethostname(nodename, strlen(nodename)) < 0) {
-			int err = errno;
-			(void) fprintf(stderr,
-			    gettext("%s: error in setting name: %s\n"),
-			    basename(progname), strerror(err));
-			exit(1);
+		if (fflag)
+			usage();	/* can't set fqdn this way */
+		if (dflag) {
+			char *domain = argv[optind];
+			if (setdomainname(domain, strlen(domain)) < 0) {
+				int err = errno;
+				(void) fprintf(stderr,
+				    gettext("%s: error setting domain: %s\n"),
+				    basename(progname), strerror(err));
+				exit(1);
+			}
+		} else {
+			char *hostname = argv[optind];
+			if (sethostname(hostname, strlen(hostname)) < 0) {
+				int err = errno;
+				(void) fprintf(stderr,
+				    gettext("%s: error setting hostname: %s\n"),
+				    basename(progname), strerror(err));
+				exit(1);
+			}
 		}
 	}
 	return (0);
--- old/usr/src/man/man1/hostname.1	2016-04-21 02:41:40.521990981 +0100
+++ new/usr/src/man/man1/hostname.1	2016-04-21 02:41:40.526363252 +0100
@@ -1,23 +1,29 @@
 '\" te
 .\" Copyright (c) 1992, Sun Microsystems, Inc.
+.\" Copyright 2016 RackTop Systems.
 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH HOSTNAME 1 "Sep 14, 1992"
+.TH HOSTNAME 1 "May 10, 2016"
 .SH NAME
 hostname \- set or print name of current host system
 .SH SYNOPSIS
 .LP
 .nf
-\fB/usr/bin/hostname\fR [\fIname-of-host\fR]
+\fB/usr/bin/hostname\fR [\fI-d\fR | \fI-f\fR] [\fIdomain\fR | \fIhostname\fR]
 .fi
 
 .SH DESCRIPTION
 .sp
 .LP
-The \fBhostname\fR command prints the name of the current host, as given before
-the \fBlogin\fR prompt. The super-user can set the hostname by giving an
-argument.
+With no arguments th \fBhostname\fR command prints the name of the current
+host, as given before the \fBlogin\fR prompt.  If \fB-d\fR is passed the
+hostname command will instead print out the name of default domain, and if
+\fB-f\fR is passed the hostname will be fully-qualified.
+.sp
+The super-user can set the hostname (or domain name if \fB-d\fR is passed) by
+passing the new value as an additional argument.  The FQDN (fully qualified
+domain name) cannot be set using the hostname command.
 .SH SEE ALSO
 .sp
 .LP
