/*
- * The Remote User Information Lister 1.8
+ * The Remote User Information Lister
*
- * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
- *
- * This software may be freely distributed and used according to the terms
- * of the GNU General Public License. See file COPYING in any of the GNU packages.
+ * (c) 1997--2010 Martin Mares <mj@ucw.cz>
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
+#include <time.h>
#include <netinet/in.h>
#include "net.h"
static int is_uptime;
+static time_t now;
static void
puttime(int s)
}
static void
-show_uptime(char *name, struct rywho_pkt *p)
+show_uptime(char *name, struct nwho_pkt *p)
{
int i;
+ if (now - ntohl(p->server_time) >= DEFAULT_DOWN_TIME)
+ {
+ printf("%-16s down\n", name);
+ return;
+ }
printf("%-16s up ", name);
puttime(ntohl(p->uptime));
printf(" load");
}
static void
-show_users(char *name, struct rywho_pkt *p)
+show_users(char *name, struct nwho_pkt *p)
{
int u;
int m = ntohl(p->num_users);
struct userinfo *i;
+ if (now - ntohl(p->server_time) >= DEFAULT_DOWN_TIME)
+ return;
for(u=0; u<m; u++)
{
i = &p->users[u];
- printf("%-8.8s %-3s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
+ printf("%-8.8s %-7s %c %-16s ", i->name, i->con, (i->mesg_y ? ' ' : '-'), name);
puttime(ntohl(i->login_time));
putchar(' ');
puttime(ntohl(i->idle_time));
{
DIR *d;
struct dirent *e;
- struct rywho_pkt pkt;
+ struct nwho_pkt pkt;
int fd, r;
int is = 0;
- if (chdir(YWHO_SPOOL_DIR) < 0)
+ if (chdir(NWHO_SPOOL_DIR) < 0)
{
- fprintf(stderr, "chdir(" YWHO_SPOOL_DIR "): %m\n");
+ fprintf(stderr, "chdir(" NWHO_SPOOL_DIR "): %m\n");
exit(1);
}
d = opendir(".");
}
r = read(fd, &pkt, sizeof(pkt));
close(fd);
- if (r < sizeof(struct rywho_pkt) - MAX_USERS*sizeof(struct userinfo)
- || r != sizeof(struct rywho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
+ if (r < sizeof(struct nwho_pkt) - MAX_USERS*sizeof(struct userinfo)
+ || pkt.magic != htonl(NWHO_MAGIC)
+ || r != sizeof(struct nwho_pkt) - (MAX_USERS - ntohl(pkt.num_users))*sizeof(struct userinfo))
{
fprintf(stderr, "%s: Malformed record\n", e->d_name);
continue;
return 1;
}
if (!is_uptime)
- puts("Name Li M Where LogT IdleT");
+ puts("Name Li M Where LogT IdleT");
+ now = time(NULL);
scan();
return 0;
}