--- src/radwho.c.orig Wed Oct 6 23:13:29 1999 +++ src/radwho.c Fri Mar 10 23:06:27 2000 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -34,18 +35,20 @@ * Header above output and format. */ char *hdr1 = -"Login Name What TTY When From Location"; -char *ufmt1 = "%-10.10s %-17.17s %-5.5s %-4.4s %-9.9s %-9.9s %-.16s%s"; +"Login Name What TTY When From Location"; +char *ufmt1 = "%-16.16s %-17.17s %-5.5s %-4.4s %-9.9s %-9.9s %-.*s%s"; char *ufmt1r = "%s,%s,%s,%s,%s,%s,%s%s"; -char *rfmt1 = "%-10.10s %-17.17s %-5.5s S%-3d %-9.9s %-9.9s %-.19s%s"; +char *rfmt1 = "%-16.16s %-17.17s %-5.5s S%-3d %-9.9s %-9.9s %-.*s%s"; char *rfmt1r = "%s,%s,%s,S%d,%s,%s,%s%s"; +#define FMT1_HOST_SIZE 13 char *hdr2 = -"Login Port What When From Location"; -char *ufmt2 = "%-10.10s %-7.7d %-9.9s %-13.13s %-10.10s %-.16s%s"; +"Login Port What When From Location"; +char *ufmt2 = "%-16.16s %-7.7s %-9.9s %-13.13s %-10.10s %-.*s%s"; char *ufmt2r = "%s,%d,%s,%s,%s,%s%s"; -char *rfmt2 = "%-10.10s S%-5d %-9.9s %-13.13s %-10.10s %-.28s%s"; +char *rfmt2 = "%-16.16s S%-6d %-9.9s %-13.13s %-10.10s %-.*s%s"; char *rfmt2r = "%s,S%d,%s,%s,%s,%s%s"; +#define FMT2_HOST_SIZE 19 char *eol = "\n"; NAS *naslist; @@ -301,7 +304,8 @@ return tmp; } if (strncmp(tty, "cu", 2) == 0) { - return tmp + 2; + sprintf(tmp, "%.15s", tty + 2); + return tmp; } return "??"; } @@ -363,6 +367,8 @@ */ int main(int argc, char **argv) { + struct winsize ws; + int extra_width = 0; FILE *fp; struct radutmp rt; struct utmp ut; @@ -378,6 +384,11 @@ char *p, *q; int c; + ioctl(0, TIOCGWINSZ, &ws); + if (ws.ws_col >= 80) { + extra_width = ws.ws_col - 80; + } + while((c = getopt(argc, argv, "flhnsipcr")) != EOF) switch(c) { case 'f': fingerd++; @@ -465,14 +476,17 @@ while(fread(&ut, sizeof(ut), 1, fp) == 1) { #ifdef USER_PROCESS if (ut.ut_user[0] && ut.ut_line[0] && - ut.ut_type == USER_PROCESS) { + ut.ut_type == USER_PROCESS) #else - if (ut.ut_user[0] && ut.ut_line[0]) { + if (ut.ut_user[0] && ut.ut_line[0]) #endif - if (showname) + { + strncpy(inbuf, ut.ut_name, UT_NAMESIZE); + inbuf[UT_NAMESIZE] = '\0'; + if (showname) printf((rawoutput == 0? ufmt1: ufmt1r), - ut.ut_name, - fullname(ut.ut_name), + inbuf, + fullname(inbuf), "shell", ttyshort(ut.ut_line), #ifdef __svr4__ @@ -481,10 +495,11 @@ dotime(ut.ut_time), #endif ut.ut_host, + FMT1_HOST_SIZE + extra_width, myname, eol); else printf((rawoutput==0? ufmt2:ufmt2r), - ut.ut_name, + inbuf, ttyshort(ut.ut_line), "shell", #ifdef __svr4__ @@ -493,6 +508,7 @@ dotime(ut.ut_time), #endif ut.ut_host, + FMT2_HOST_SIZE + extra_width, myname, eol); } } @@ -530,6 +546,7 @@ rt.nas_port, dotime(rt.time), nasname(ntohl(rt.nas_address)), + FMT1_HOST_SIZE + extra_width, hostname(rt.framed_address), eol); else printf((rawoutput == 0? rfmt2: rfmt2r), @@ -538,6 +555,7 @@ proto(rt.proto, rt.porttype), dotime(rt.time), nasname(ntohl(rt.nas_address)), + FMT2_HOST_SIZE + extra_width, hostname(rt.framed_address), eol); } }