2 * The Remote User Information Lister
4 * (c) 1997--2002 Martin Mares <mj@ucw.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.
17 #include <netinet/in.h>
18 #include <asm/types.h>
38 printf("%02d.%02d", h, m);
44 printf("%2dd%02d", d, h);
52 show_uptime(char *name, struct rywho_pkt *p)
56 if (p->server_time - now >= DEFAULT_DOWN_TIME)
58 printf("%-16s down\n", name);
61 printf("%-16s up ", name);
62 puttime(ntohl(p->uptime));
66 int l = ntohl(p->avl[i]);
67 printf(" %2d.%02d", l/100, l%100);
69 printf(" %3d users\n", (int) ntohl(p->num_users));
73 show_users(char *name, struct rywho_pkt *p)
76 int m = ntohl(p->num_users);
79 if (p->server_time - now >= DEFAULT_DOWN_TIME)
84 printf("%-8.8s %-7s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
85 puttime(ntohl(i->login_time));
87 puttime(ntohl(i->idle_time));
91 printf("%s: MAX_USERS reached!\n", name);
103 if (chdir(NWHO_SPOOL_DIR) < 0)
105 fprintf(stderr, "chdir(" NWHO_SPOOL_DIR "): %m\n");
114 while (e = readdir(d))
115 if (e->d_name[0] != '.')
117 fd = open(e->d_name, O_RDONLY);
120 fprintf(stderr, "%s: %m\n", e->d_name);
123 r = read(fd, &pkt, sizeof(pkt));
125 if (r < sizeof(struct rywho_pkt) - MAX_USERS*sizeof(struct userinfo)
126 || pkt.magic != htonl(NWHO_MAGIC)
127 || r != sizeof(struct rywho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
129 fprintf(stderr, "%s: Malformed record\n", e->d_name);
132 (is_uptime ? show_uptime : show_users)(e->d_name, &pkt);
137 puts("No data available.");
141 main(int argc, char **argv)
143 if (strstr(argv[0], "uptime"))
147 fprintf(stderr, "Usage: %s\n", argv[0]);
151 puts("Name Li M Where LogT IdleT");