--- hostname.1.ori 2016-08-12 02:09:38.000000000 +0200 +++ hostname.1 2016-09-21 08:54:07.714869000 +0200 @@ -37,7 +37,7 @@ .Nd set or print name of current host system .Sh SYNOPSIS .Nm -.Op Fl fs +.Op Fl fsd .Op Ar name-of-host .Sh DESCRIPTION The @@ -62,6 +62,8 @@ .It Fl s Trim off any domain information from the printed name. +.It Fl d +Only print domain information. .El .Sh SEE ALSO .Xr gethostname 3 , --- hostname.c.ori 2016-08-12 02:09:38.000000000 +0200 +++ hostname.c 2016-09-21 08:51:54.767720000 +0200 @@ -54,11 +54,12 @@ int main(int argc, char *argv[]) { - int ch, sflag; + int ch, sflag, dflag; char *p, hostname[MAXHOSTNAMELEN]; sflag = 0; - while ((ch = getopt(argc, argv, "fs")) != -1) + dflag = 0; + while ((ch = getopt(argc, argv, "fsd")) != -1) switch (ch) { case 'f': /* @@ -70,6 +71,9 @@ case 's': sflag = 1; break; + case 'd': + dflag = 1; + break; case '?': default: usage(); @@ -91,6 +95,11 @@ if (p != NULL) *p = '\0'; } + else if (dflag) { + p = strchr(hostname, '.'); + if (p != NULL) + strcpy(hostname,++p); + } (void)printf("%s\n", hostname); } exit(0);