[PATCH] Add support for "O" modifier to display DNS domainname.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 login-utils/agetty.8 |    5 ++++-
 login-utils/agetty.c |   28 ++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/login-utils/agetty.8 b/login-utils/agetty.8
index 69be5f2..dc18691 100644
--- a/login-utils/agetty.8
+++ b/login-utils/agetty.8
@@ -217,7 +217,10 @@ n
 Insert the nodename of the machine, also known as the hostname.
 .TP
 o
-Insert the domainname of the machine.
+Insert the NIS domainname of the machine.
+.TP
+O
+Insert the DNS domainname of the machine.
 .TP
 r
 Insert the release number of the OS, eg. 1.1.9.
diff --git a/login-utils/agetty.c b/login-utils/agetty.c
index eb9fab5..1b2349b 100644
--- a/login-utils/agetty.c
+++ b/login-utils/agetty.c
@@ -30,6 +30,7 @@
 #include <getopt.h>
 #include <time.h>
 #include <sys/file.h>
+#include <netdb.h>
 #include "xstrncpy.h"
 #include "nls.h"
 
@@ -122,6 +123,15 @@
 #define	BUFSIZ		1024
 #endif
 
+/* set a maximum length for the hostname,  */
+#ifdef HOST_NAME_MAX
+# define HOSTNAME_LENGTH HOST_NAME_MAX  /* defined by POSIX */
+#elif defined(MAXHOSTNAMELEN)
+# define HOSTNAME_LENGTH MAXHOSTNAMELEN /* implemented in current Unix-versions */
+#else
+# define HOSTNAME_LENGTH 500            /* some arbitrary value */
+#endif
+
  /*
   * When multiple baud rates are specified on the command line, the first one
   * we will try is the first one specified.
@@ -879,6 +889,24 @@ do_prompt(op, tp)
 		   }
 		  break;
 
+		  case 'O':
+		   {
+		     char *domain = NULL;
+		     char host[HOSTNAME_LENGTH + 1];
+		     struct hostent *hp = NULL;
+
+		     if (gethostname(host, HOSTNAME_LENGTH) || !(hp = gethostbyname(host))) {
+			domain = " unknown_domain";
+		     } else {
+			/* get the substring after the first . */
+			domain = strchr(hp->h_name, '.');
+			if (domain == NULL)
+			    domain = ".(none)";
+		     }
+		     printf("%s", ++domain);
+		   }
+		  break;
+
 		  case 'd':
 		  case 't':
 		    {
-- 
1.5.1

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux