--- agetty.c 2002-07-29 09:36:42.000000000 +0200 +++ /home/users/genone/projekte/misc/agetty-with-dns.c 2003-07-13 04:24:01.000000000 +0200 @@ -30,6 +30,7 @@ #include #include #include +#include #include "xstrncpy.h" #include "nls.h" @@ -122,6 +123,17 @@ #define BUFSIZ 1024 #endif +/* set a maximum length for the hostname, */ +#ifdef HOST_NAME_MAX + /* defined by POSIX */ + #define HOSTNAME_LENGTH HOST_NAME_MAX +#elif defined(MAXHOSTNAMELEN) + /* implemented in current Unix-versions */ + #define HOSTNAME_LENGTH MAXHOSTNAMELEN +#else + #define HOSTNAME_LENGTH 500 +#endif + /* * When multiple baud rates are specified on the command line, the first one * we will try is the first one specified. @@ -878,7 +890,25 @@ printf ("%s", domainname); } 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': {