#include "opt.h"
#include "str.h"
-#include <arpa/inet.h> /* inet_aton() */
#include <netdb.h> /* struct addrinfo */
#include <assert.h>
#include <errno.h>
}
#ifndef s6_addr32
+# ifdef sun
+/*
+ * http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/netinet/in.h#130
+ */
+# define s6_addr32 _S6_un._S6_u32
+# else
/* Covers OpenBSD and FreeBSD. The macro __USE_GNU has
* taken care of GNU/Linux and GNU/kfreebsd. */
-# define s6_addr32 __u6_addr.__u6_addr32
+# define s6_addr32 __u6_addr.__u6_addr32
+# endif
#endif
/*
MAKE_BUCKET(b, h, host);
h->addr = CASTKEY(struct addr);
h->dns = NULL;
- h->last_seen = now;
+ h->lastseen = 0;
memset(&h->mac_addr, 0, sizeof(h->mac_addr));
h->ports_tcp = NULL;
h->ports_udp = NULL;
b->in, b->out, b->total);
if (opt_want_lastseen) {
- time_t last_t = b->u.host.last_seen;
- struct str *lastseen = NULL;
+ time_t last_t = b->u.host.lastseen;
+ struct str *last_str = NULL;
- if (now >= last_t)
- lastseen = length_of_time(now - last_t);
+ if ((now >= last_t) && (last_t > 0))
+ last_str = length_of_time(now - last_t);
str_append(buf,
" <td class=\"num\">");
- if (lastseen == NULL)
- str_append(buf, "(clock error)");
- else {
- str_appendstr(buf, lastseen);
- str_free(lastseen);
+ if (last_str == NULL) {
+ if (last_t == 0)
+ str_append(buf, "(never)");
+ else
+ str_append(buf, "(clock error)");
+ } else {
+ str_appendstr(buf, last_str);
+ str_free(last_str);
}
str_append(buf,
"</td>");
start = 0;
end = ht->count;
} else
- end = min(ht->count, (uint32_t)start+MAX_ENTRIES);
+ end = MIN(ht->count, (uint32_t)start+MAX_ENTRIES);
str_appendf(buf, "(%u-%u of %u)<br>\n", start+1, end, ht->count);
qsort_buckets(table, ht->count, start, end, sort);
"<p>\n"
"<b>Last seen:</b> ");
- ls = h->u.host.last_seen;
+ ls = h->u.host.lastseen;
if (strftime(ls_when, sizeof(ls_when),
"%Y-%m-%d %H:%M:%S %Z%z", localtime(&ls)) != 0)
str_append(buf, ls_when);
- if (h->u.host.last_seen <= now) {
- ls_len = length_of_time(now - h->u.host.last_seen);
+ if (h->u.host.lastseen <= now) {
+ ls_len = length_of_time(now - h->u.host.lastseen);
str_append(buf, " (");
str_appendstr(buf, ls_len);
str_free(ls_len);
if (ver > 1) {
uint64_t t;
if (!read64(fd, &t)) return 0;
- host->u.host.last_seen = (time_t)t;
+ host->u.host.lastseen = (time_t)t;
}
assert(sizeof(host->u.host.mac_addr) == 6);
if (!writeaddr(fd, &(b->u.host.addr))) return 0;
- if (!write64(fd, (uint64_t)(b->u.host.last_seen))) return 0;
+ if (!write64(fd, (uint64_t)(b->u.host.lastseen))) return 0;
assert(sizeof(b->u.host.mac_addr) == 6);
if (!writen(fd, b->u.host.mac_addr, sizeof(b->u.host.mac_addr)))