2 * The Remote User Information Lister
4 * (c) 1997--2010 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>
37 printf("%02d.%02d", h, m);
43 printf("%2dd%02d", d, h);
51 show_uptime(char *name, struct rywho_pkt *p)
55 if (now - ntohl(p->server_time) >= DEFAULT_DOWN_TIME)
57 printf("%-16s down\n", name);
60 printf("%-16s up ", name);
61 puttime(ntohl(p->uptime));
65 int l = ntohl(p->avl[i]);
66 printf(" %2d.%02d", l/100, l%100);
68 printf(" %3d users\n", (int) ntohl(p->num_users));
72 show_users(char *name, struct rywho_pkt *p)
75 int m = ntohl(p->num_users);
78 if (now - ntohl(p->server_time) >= DEFAULT_DOWN_TIME)
83 printf("%-8.8s %-7s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
84 puttime(ntohl(i->login_time));
86 puttime(ntohl(i->idle_time));
90 printf("%s: MAX_USERS reached!\n", name);
102 if (chdir(NWHO_SPOOL_DIR) < 0)
104 fprintf(stderr, "chdir(" NWHO_SPOOL_DIR "): %m\n");
113 while (e = readdir(d))
114 if (e->d_name[0] != '.')
116 fd = open(e->d_name, O_RDONLY);
119 fprintf(stderr, "%s: %m\n", e->d_name);
122 r = read(fd, &pkt, sizeof(pkt));
124 if (r < sizeof(struct rywho_pkt) - MAX_USERS*sizeof(struct userinfo)
125 || pkt.magic != htonl(NWHO_MAGIC)
126 || r != sizeof(struct rywho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
128 fprintf(stderr, "%s: Malformed record\n", e->d_name);
131 (is_uptime ? show_uptime : show_users)(e->d_name, &pkt);
136 puts("No data available.");
140 main(int argc, char **argv)
142 if (strstr(argv[0], "uptime"))
146 fprintf(stderr, "Usage: %s\n", argv[0]);
150 puts("Name Li M Where LogT IdleT");