2 * The Remote User Information Lister
4 * (c) 1997--2010 Martin Mares <mj@ucw.cz>
14 #include <netinet/in.h>
34 printf("%02d.%02d", h, m);
40 printf("%2dd%02d", d, h);
48 show_uptime(char *name, struct rywho_pkt *p)
52 if (now - ntohl(p->server_time) >= DEFAULT_DOWN_TIME)
54 printf("%-16s down\n", name);
57 printf("%-16s up ", name);
58 puttime(ntohl(p->uptime));
62 int l = ntohl(p->avl[i]);
63 printf(" %2d.%02d", l/100, l%100);
65 printf(" %3d users\n", (int) ntohl(p->num_users));
69 show_users(char *name, struct rywho_pkt *p)
72 int m = ntohl(p->num_users);
75 if (now - ntohl(p->server_time) >= DEFAULT_DOWN_TIME)
80 printf("%-8.8s %-7s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
81 puttime(ntohl(i->login_time));
83 puttime(ntohl(i->idle_time));
87 printf("%s: MAX_USERS reached!\n", name);
99 if (chdir(NWHO_SPOOL_DIR) < 0)
101 fprintf(stderr, "chdir(" NWHO_SPOOL_DIR "): %m\n");
110 while (e = readdir(d))
111 if (e->d_name[0] != '.')
113 fd = open(e->d_name, O_RDONLY);
116 fprintf(stderr, "%s: %m\n", e->d_name);
119 r = read(fd, &pkt, sizeof(pkt));
121 if (r < sizeof(struct rywho_pkt) - MAX_USERS*sizeof(struct userinfo)
122 || pkt.magic != htonl(NWHO_MAGIC)
123 || r != sizeof(struct rywho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
125 fprintf(stderr, "%s: Malformed record\n", e->d_name);
128 (is_uptime ? show_uptime : show_users)(e->d_name, &pkt);
133 puts("No data available.");
137 main(int argc, char **argv)
139 if (strstr(argv[0], "uptime"))
143 fprintf(stderr, "Usage: %s\n", argv[0]);
147 puts("Name Li M Where LogT IdleT");