diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-01-20 02:10:25 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-01-20 02:10:25 +0800 |
commit | ccac6983bd25c68d046c82f9168be448d12da721 (patch) | |
tree | b173d4fb13eebc0a887fa063848fccd9087094e0 /util/bbsrf.c | |
parent | bb629566335ef1ea90859bd467028d52e67e0f81 (diff) | |
download | pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.tar pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.tar.gz pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.tar.bz2 pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.tar.lz pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.tar.xz pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.tar.zst pttbbs-ccac6983bd25c68d046c82f9168be448d12da721.zip |
generic support for ssh hostname via SSH_CLIENT env (with support for ipv6 like IPs)
fix shell mode proctitle
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2414 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/bbsrf.c')
-rw-r--r-- | util/bbsrf.c | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/util/bbsrf.c b/util/bbsrf.c index c3bf44a9..4999f993 100644 --- a/util/bbsrf.c +++ b/util/bbsrf.c @@ -39,36 +39,17 @@ /* fill the hid with from hostname */ void gethid(char *hid, char *tty) { - int fd; - char *tp; -#ifdef Solaris - struct utmpx data; -#else - struct utmp data; -#endif + char frombuf[100]; - gethostname(hid, MAX_HOMENAME_LEN); - hid[MAX_HOMENAME_LEN] = '\0'; - tp = strrchr(tty, '/') + 1; - if (tp && strlen(tp) == 5) - { - fd = open(U_FILE, O_RDONLY); - if (fd < 0) - syslog(LOG_ERR, "%s: %m", U_FILE); - else - { - while (read(fd, &data, sizeof(data)) == sizeof(data)) - if (strcmp(data.ut_line, tp) == 0) - { - if (data.ut_host[0]) { - strncpy(hid, data.ut_host, MAX_HOMENAME_LEN); - hid[MAX_HOMENAME_LEN] = '\0'; - } - break; - } - close(fd); - } - } + if (getenv("SSH_CLIENT")) + sscanf(getenv("SSH_CLIENT"), "%s", frombuf); + else + strcpy(frombuf, "127.0.0.1"); + + if (strrchr(frombuf, ':')) + strncpy(hid, strrchr(frombuf, ':') + 1, MAX_HOMENAME_LEN); + else + strncpy(hid, frombuf, MAX_HOMENAME_LEN); } /* |