-
- b = 0;
- for (a=0; !IsEmptyStr(&buf[a]); ++a) {
- if ((buf[a]=='(')||(buf[a]==')')) ++b;
- }
- if (b<2) {
- strcpy(hbuf, ipc->ServInfo.fqdn);
- return;
- }
-
- for (a=0; a<strlen(buf); ++a) {
- if (buf[a]=='(') {
- strcpy(buf,&buf[a+1]);
- }
- }
- for (a=0; a<strlen(buf); ++a) {
- if (buf[a]==')') buf[a] = 0;
- }
-
- if (IsEmptyStr(buf)) strcpy(hbuf, ipc->ServInfo.fqdn);
- else strncpy(hbuf,buf,24);
-#else
- char *tty = ttyname(0);
-#ifdef HAVE_GETUTXLINE
- struct utmpx ut, *put;
-#else
- struct utmp ut, *put;
-#endif
-
- if (tty == NULL) {
- fail:
- safestrncpy(hbuf, ipc->ServInfo.fqdn, 24);
- return;
- }
-
- if (strncmp(tty, "/dev/", 5))
- goto fail;
-
- safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
-
-#ifdef HAVE_GETUTXLINE /* Solaris uses this */
- if ((put = getutxline(&ut)) == NULL)
-#else
- if ((put = getutline(&ut)) == NULL)
-#endif
- goto fail;
-
-#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
- if (put->ut_type == USER_PROCESS) {
-#endif
-#if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
- if (*put->ut_host)
- safestrncpy(hbuf, put->ut_host, 24);
- else
-#endif
- safestrncpy(hbuf, put->ut_line, 24);
-#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
- }
- else goto fail;
-#endif
-#endif /* HAVE_UTMP_H */