--- old/usr/src/cmd/hostname/Makefile	2016-04-21 10:52:04.291928920 +0100
+++ new/usr/src/cmd/hostname/Makefile	2016-04-21 10:52:04.297138502 +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 -lsocket
+
 .KEEP_STATE:
 
 all: $(PROG) 
--- old/usr/src/cmd/hostname/hostname.c	2016-04-21 10:52:04.436365240 +0100
+++ new/usr/src/cmd/hostname/hostname.c	2016-04-21 10:52:04.441483455 +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>
@@ -46,6 +47,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <netdb.h>
+#include <getopt.h>
 
 #ifndef	TEXT_DOMAIN		/* should be defined by cc -D */
 #define	TEXT_DOMAIN "SYS_TEST"	/* use this only if it wasn't */
@@ -56,7 +58,7 @@
 static void
 usage(void)
 {
-	(void) fprintf(stderr, gettext("usage: %s [system_name]\n"),
+	(void) fprintf(stderr, gettext("usage: %s [-fls|system_name]\n"),
 		basename(progname));
 	exit(1);
 }
@@ -66,8 +68,15 @@
 {
 	char	*nodename = NULL;
 	char    c_hostname[MAXHOSTNAMELEN];
-	int	optlet;
-	char	*optstring = "?";
+	int	optlet, optindex = 0;
+	char	*optstring = "fls";
+	int	fflag = 0, lflag = 0, sflag = 0;
+	struct	option long_options[] = {
+		{"fqdn",	no_argument,	0,	'f'	},
+		{"long",	no_argument,	0,	'l'	},
+		{"short",	no_argument,	0,	's'	},
+		{NULL,		0,		0,	0	}
+	};
 
 	(void) setlocale(LC_ALL, "");
 	(void) textdomain(TEXT_DOMAIN);
@@ -75,13 +84,31 @@
 	progname = argv[0];
 
 	opterr = 0;
-	while ((optlet = getopt(argc, argv, optstring)) != -1) {
+	while ((optlet = getopt_long(argc, argv, optstring, long_options,
+	    &optindex)) != -1) {
 		switch (optlet) {
+		case 'f':
+			fflag++;
+			break;
+		case 'l':
+			lflag++;
+			break;
+		case 's':
+			sflag++;
+			break;
 		case '?':
 			usage();
 		}
 	}
 
+	/* No flag combinations allowed */
+	if (fflag && (lflag || sflag))
+		usage();
+	if (lflag && (fflag || sflag))
+		usage();
+	if (sflag && (lflag || fflag))
+		usage();
+
 	/*
 	 * if called with no options, just print out the hostname/nodename
 	 */
@@ -91,7 +118,25 @@
 			    gettext("%s: unable to obtain hostname\n"),
 			    basename(progname));
 			exit(1);
+		}
+		if (fflag || lflag) {
+			struct addrinfo hints, *info;
+			memset(&hints, 0, sizeof (struct addrinfo));
+			hints.ai_socktype = SOCK_DGRAM;
+			hints.ai_flags = AI_CANONNAME;
+			if (getaddrinfo(c_hostname, NULL, &hints, &info) != 0) {
+				(void) fprintf(stderr,
+				    gettext("%s: unable to obtain fqdn\n"),
+				    basename(progname));
+				exit(1);
+			}
+			(void) fprintf(stdout, "%s\n", info->ai_canonname);
 		} else {
+			if (sflag) {
+				char *p = strchr(c_hostname, '.');
+				if (p != NULL)
+					*p = '\0';
+			}
 			(void) fprintf(stdout, "%s\n", c_hostname);
 		}
 	} else {
@@ -101,7 +146,10 @@
 		 */
 		if (argc > optind + 1)
 			usage();	/* too many arguments */
-
+		if (fflag || lflag)
+			usage();	/* can't set fqdn this way */
+		if (sflag)
+			usage();	/* can't set short name */
 		nodename = argv[optind];
 		if (sethostname(nodename, strlen(nodename)) < 0) {
 			int err = errno;
--- old/usr/src/man/man1/hostname.1	2016-04-21 10:52:04.587833204 +0100
+++ new/usr/src/man/man1/hostname.1	2016-04-21 10:52:04.592771056 +0100
@@ -1,15 +1,16 @@
 '\" 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 11, 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-fls\fR | \fIname-of-host\fR]
 .fi
 
 .SH DESCRIPTION
@@ -18,6 +19,21 @@
 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.
+.sp
+.SH OPTIONS
+.sp
+For compatibility long arguments are also supported.
+.sp
+.LP
+\fB-f, --fqdn\fR print out the FQDN (fully qualified domain name).
+.sp
+\fB-l, --long\fR alias for \fB-f, --fqdn\fR.
+.sp
+\fB-s, --short\fR strip domain information from hostname.
+.sp
+.LP
+The \fBhostname\fR command cannot be used to set the fqdn, long or short name.
+.sp
 .SH SEE ALSO
 .sp
 .LP
