2 * The Remote User Information Lister 1.9
4 * (c) 1997--2001 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>
17 #include <asm/types.h>
36 printf("%02d.%02d", h, m);
42 printf("%2dd%02d", d, h);
50 show_uptime(char *name, struct rywho_pkt *p)
54 printf("%-16s up ", name);
55 puttime(ntohl(p->uptime));
59 int l = ntohl(p->avl[i]);
60 printf(" %2d.%02d", l/100, l%100);
62 printf(" %3d users\n", (int) ntohl(p->num_users));
66 show_users(char *name, struct rywho_pkt *p)
69 int m = ntohl(p->num_users);
75 printf("%-8.8s %-7s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
76 puttime(ntohl(i->login_time));
78 puttime(ntohl(i->idle_time));
82 printf("%s: MAX_USERS reached!\n", name);
94 if (chdir(NWHO_SPOOL_DIR) < 0)
96 fprintf(stderr, "chdir(" NWHO_SPOOL_DIR "): %m\n");
105 while (e = readdir(d))
106 if (e->d_name[0] != '.')
108 fd = open(e->d_name, O_RDONLY);
111 fprintf(stderr, "%s: %m\n", e->d_name);
114 r = read(fd, &pkt, sizeof(pkt));
116 if (r < sizeof(struct rywho_pkt) - MAX_USERS*sizeof(struct userinfo)
117 || pkt.magic != htonl(NWHO_MAGIC)
118 || r != sizeof(struct rywho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
120 fprintf(stderr, "%s: Malformed record\n", e->d_name);
123 (is_uptime ? show_uptime : show_users)(e->d_name, &pkt);
128 puts("No data available.");
132 main(int argc, char **argv)
134 if (strstr(argv[0], "uptime"))
138 fprintf(stderr, "Usage: %s\n", argv[0]);
142 puts("Name Li M Where LogT IdleT");