2 * The Remote User Information Lister 1.8
4 * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU General Public License. See file COPYING in any of the GNU packages.
16 #include <netinet/in.h>
35 printf("%02d.%02d", h, m);
41 printf("%2dd%02d", d, h);
49 show_uptime(char *name, struct rywho_pkt *p)
53 printf("%-16s up ", name);
54 puttime(ntohl(p->uptime));
58 int l = ntohl(p->avl[i]);
59 printf(" %2d.%02d", l/100, l%100);
65 show_users(char *name, struct rywho_pkt *p)
68 int m = ntohl(p->num_users);
74 printf("%-8s %-3s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
75 puttime(ntohl(i->login_time));
77 puttime(ntohl(i->idle_time));
81 printf("%s: MAX_USERS reached!\n", name);
93 if (chdir(YWHO_SPOOL_DIR) < 0)
95 fprintf(stderr, "chdir(" YWHO_SPOOL_DIR "): %m\n");
104 while (e = readdir(d))
105 if (e->d_name[0] != '.')
107 fd = open(e->d_name, O_RDONLY);
110 fprintf(stderr, "%s: %m\n", e->d_name);
113 r = read(fd, &pkt, sizeof(pkt));
115 if (r <= sizeof(struct rywho_pkt) - MAX_USERS*sizeof(struct userinfo)
116 || r != sizeof(struct rywho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
118 fprintf(stderr, "%s: Malformed record\n", e->d_name);
121 (is_uptime ? show_uptime : show_users)(e->d_name, &pkt);
126 puts("No data available.");
130 main(int argc, char **argv)
132 if (strstr(argv[0], "uptime"))
136 fprintf(stderr, "Usage: %s\n", argv[0]);
140 puts("Name Li M Where LogT IdleT");