#include <stdlib.h> /* for free */
#include <string.h> /* for memcpy */
-uint64_t total_packets = 0, total_bytes = 0;
+uint64_t acct_total_packets = 0, acct_total_bytes = 0;
static int using_localnet4 = 0, using_localnet6 = 0;
static struct addr localnet4, localmask4, localnet6, localmask6;
#endif
/* Totals. */
- total_packets++;
- total_bytes += sm->len;
+ acct_total_packets++;
+ acct_total_bytes += sm->len;
/* Graphs. */
dir_out = addr_is_local(&(sm->src));
graph_acct((uint64_t)sm->len, GRAPH_IN);
}
- if (hosts_max == 0) return; /* skip per-host accounting */
+ if (opt_hosts_max == 0) return; /* skip per-host accounting */
/* Hosts. */
hosts_db_reduce();
pd->total += sm->len;
}
- if (ports_max == 0) return; /* skip ports accounting */
+ if (opt_ports_max == 0) return; /* skip ports accounting */
/* Ports. */
switch (sm->proto) {
case IPPROTO_TCP:
- if (sm->src_port <= highest_port) {
+ if (sm->src_port <= opt_highest_port) {
ps = host_get_port_tcp(hs, sm->src_port);
ps->out += sm->len;
ps->total += sm->len;
}
- if (sm->dst_port <= highest_port) {
+ if (sm->dst_port <= opt_highest_port) {
pd = host_get_port_tcp(hd, sm->dst_port);
pd->in += sm->len;
pd->total += sm->len;
break;
case IPPROTO_UDP:
- if (sm->src_port <= highest_port) {
+ if (sm->src_port <= opt_highest_port) {
ps = host_get_port_udp(hs, sm->src_port);
ps->out += sm->len;
ps->total += sm->len;
}
- if (sm->dst_port <= highest_port) {
+ if (sm->dst_port <= opt_highest_port) {
pd = host_get_port_udp(hd, sm->dst_port);
pd->in += sm->len;
pd->total += sm->len;
struct pktsummary;
-extern uint64_t total_packets, total_bytes;
+extern uint64_t acct_total_packets, acct_total_bytes;
void acct_init_localnet(const char *spec);
void acct_for(const struct pktsummary * const sm);
-extern unsigned int highest_port;
-
/* vim:set ts=3 sw=3 tw=78 expandtab: */
#include <string.h>
#include <unistd.h>
-extern int want_pppoe, want_macs, want_hexdump, want_snaplen, wait_secs;
-
/* The cap process life-cycle:
*
* Init - cap_init()
errbuf);
if (pcap != NULL) break; /* success! */
- if ((wait_secs != -1) && strstr(errbuf, "device is not up")) {
- if ((wait_secs > 0) && (waited >= wait_secs))
+ if ((opt_wait_secs != -1) && strstr(errbuf, "device is not up")) {
+ if ((opt_wait_secs > 0) && (waited >= opt_wait_secs))
errx(1, "waited %d secs, giving up: pcap_open_live(): %s",
waited, errbuf);
/* Work out the linktype and what snaplen we need. */
linktype = pcap_datalink(pcap);
verbosef("linktype is %d", linktype);
- if ((linktype == DLT_EN10MB) && want_macs)
- show_mac_addrs = 1;
+ if ((linktype == DLT_EN10MB) && opt_want_macs)
+ hosts_db_show_macs = 1;
linkhdr = getlinkhdr(linktype);
if (linkhdr == NULL)
errx(1, "unknown linktype %d", linktype);
if (linkhdr->handler == NULL)
errx(1, "no handler for linktype %d", linktype);
snaplen = getsnaplen(linkhdr);
- if (want_pppoe) {
+ if (opt_want_pppoe) {
snaplen += PPPOE_HDR_LEN;
if (linktype != DLT_EN10MB)
errx(1, "can't do PPPoE decoding on a non-Ethernet linktype");
*/
snaplen = max(snaplen, 96);
#endif
- if (want_snaplen > -1)
- snaplen = want_snaplen;
+ if (opt_want_snaplen > -1)
+ snaplen = opt_want_snaplen;
verbosef("using snaplen %d", snaplen);
/* Close and re-open pcap to use the new snaplen. */
#endif
}
-unsigned int pkts_recv = 0, pkts_drop = 0;
+unsigned int cap_pkts_recv = 0, cap_pkts_drop = 0;
static void
cap_stats_update(void)
return;
}
- pkts_recv = ps.ps_recv;
- pkts_drop = ps.ps_drop;
+ cap_pkts_recv = ps.ps_recv;
+ cap_pkts_drop = ps.ps_drop;
}
/*
static void
callback(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
{
- if (want_hexdump) hexdump(bytes, h->caplen);
+ if (opt_want_hexdump) hexdump(bytes, h->caplen);
linkhdr->handler(user, h, bytes);
}
if (linkhdr->handler == NULL)
errx(1, "no handler for linktype %d", linktype);
if (linktype == DLT_EN10MB) /* FIXME: impossible with capfile? */
- show_mac_addrs = 1;
+ hosts_db_show_macs = 1;
/* Set filter expression, if any. */ /* FIXME: factor! */
if (filter != NULL)
#include <sys/time.h> /* FreeBSD 4 needs this for struct timeval */
#include <sys/select.h>
-extern unsigned int pkts_recv, pkts_drop;
+extern unsigned int cap_pkts_recv, cap_pkts_drop;
void cap_init(const char *device, const char *filter, int promisc);
void cap_fd_set(fd_set *read_set, int *max_fd,
return n;
}
-const char *interface = NULL;
-static void cb_interface(const char *arg) { interface = arg; }
+const char *opt_interface = NULL;
+static void cb_interface(const char *arg) { opt_interface = arg; }
-const char *capfile = NULL;
-static void cb_capfile(const char *arg) { capfile = arg; }
+const char *opt_capfile = NULL;
+static void cb_capfile(const char *arg) { opt_capfile = arg; }
-int want_snaplen = -1;
+int opt_want_snaplen = -1;
static void cb_snaplen(const char *arg)
-{ want_snaplen = (int)parsenum(arg, 0); }
+{ opt_want_snaplen = (int)parsenum(arg, 0); }
-int want_pppoe = 0;
-static void cb_pppoe(const char *arg _unused_) { want_pppoe = 1; }
+int opt_want_pppoe = 0;
+static void cb_pppoe(const char *arg _unused_) { opt_want_pppoe = 1; }
-static void cb_syslog(const char *arg _unused_) { want_syslog = 1; }
+int opt_want_syslog = 0;
+static void cb_syslog(const char *arg _unused_) { opt_want_syslog = 1; }
-static void cb_verbose(const char *arg _unused_) { want_verbose = 1; }
+int opt_want_verbose = 0;
+static void cb_verbose(const char *arg _unused_) { opt_want_verbose = 1; }
-int want_daemonize = 1;
-static void cb_no_daemon(const char *arg _unused_) { want_daemonize = 0; }
+int opt_want_daemonize = 1;
+static void cb_no_daemon(const char *arg _unused_) { opt_want_daemonize = 0; }
-int want_promisc = 1;
-static void cb_no_promisc(const char *arg _unused_) { want_promisc = 0; }
+int opt_want_promisc = 1;
+static void cb_no_promisc(const char *arg _unused_) { opt_want_promisc = 0; }
-int want_dns = 1;
-static void cb_no_dns(const char *arg _unused_) { want_dns = 0; }
+int opt_want_dns = 1;
+static void cb_no_dns(const char *arg _unused_) { opt_want_dns = 0; }
-int want_macs = 1;
-static void cb_no_macs(const char *arg _unused_) { want_macs = 0; }
+int opt_want_macs = 1;
+static void cb_no_macs(const char *arg _unused_) { opt_want_macs = 0; }
-int want_lastseen = 1;
-static void cb_no_lastseen(const char *arg _unused_) { want_lastseen = 0; }
+int opt_want_lastseen = 1;
+static void cb_no_lastseen(const char *arg _unused_) { opt_want_lastseen = 0; }
-unsigned short bindport = 667;
+unsigned short opt_bindport = 667;
static void cb_port(const char *arg)
-{ bindport = (unsigned short)parsenum(arg, 65536); }
+{ opt_bindport = (unsigned short)parsenum(arg, 65536); }
-const char *bindaddr = NULL;
+const char *opt_bindaddr = NULL;
static void cb_bindaddr(const char *arg)
{
struct addrinfo hints, *ai;
errx(1, "malformed address \"%s\"", arg);
freeaddrinfo(ai);
- bindaddr = arg;
+ opt_bindaddr = arg;
}
-const char *filter = NULL;
-static void cb_filter(const char *arg) { filter = arg; }
+const char *opt_filter = NULL;
+static void cb_filter(const char *arg) { opt_filter = arg; }
static void cb_local(const char *arg) { acct_init_localnet(arg); }
-const char *chroot_dir = NULL;
-static void cb_chroot(const char *arg) { chroot_dir = arg; }
+const char *opt_chroot_dir = NULL;
+static void cb_chroot(const char *arg) { opt_chroot_dir = arg; }
-const char *base = NULL;
-static void cb_base(const char *arg) { base = arg; }
+const char *opt_base = NULL;
+static void cb_base(const char *arg) { opt_base = arg; }
-const char *privdrop_user = NULL;
-static void cb_user(const char *arg) { privdrop_user = arg; }
+const char *opt_privdrop_user = NULL;
+static void cb_user(const char *arg) { opt_privdrop_user = arg; }
const char *daylog_fn = NULL;
static void cb_daylog(const char *arg)
{
- if (chroot_dir == NULL)
+ if (opt_chroot_dir == NULL)
errx(1, "the daylog file is relative to the chroot.\n"
"You must specify a --chroot dir before you can use --daylog.");
else
const char *import_fn = NULL;
static void cb_import(const char *arg)
{
- if (chroot_dir == NULL)
+ if (opt_chroot_dir == NULL)
errx(1, "the import file is relative to the chroot.\n"
"You must specify a --chroot dir before you can use --import.");
else
const char *export_fn = NULL;
static void cb_export(const char *arg)
{
- if ((chroot_dir == NULL) && (capfile == NULL))
+ if ((opt_chroot_dir == NULL) && (opt_capfile == NULL))
errx(1, "the export file is relative to the chroot.\n"
"You must specify a --chroot dir before you can use --export.");
else
static const char *pid_fn = NULL;
static void cb_pidfile(const char *arg)
{
- if (chroot_dir == NULL)
+ if (opt_chroot_dir == NULL)
errx(1, "the pidfile is relative to the chroot.\n"
"You must specify a --chroot dir before you can use --pidfile.");
else
pid_fn = arg;
}
-unsigned int hosts_max = 1000;
+unsigned int opt_hosts_max = 1000;
static void cb_hosts_max(const char *arg)
-{ hosts_max = parsenum(arg, 0); }
+{ opt_hosts_max = parsenum(arg, 0); }
-unsigned int hosts_keep = 500;
+unsigned int opt_hosts_keep = 500;
static void cb_hosts_keep(const char *arg)
-{ hosts_keep = parsenum(arg, 0); }
+{ opt_hosts_keep = parsenum(arg, 0); }
-unsigned int ports_max = 200;
+unsigned int opt_ports_max = 200;
static void cb_ports_max(const char *arg)
-{ ports_max = parsenum(arg, 65536); }
+{ opt_ports_max = parsenum(arg, 65536); }
-unsigned int ports_keep = 30;
+unsigned int opt_ports_keep = 30;
static void cb_ports_keep(const char *arg)
-{ ports_keep = parsenum(arg, 65536); }
+{ opt_ports_keep = parsenum(arg, 65536); }
-unsigned int highest_port = 65535;
+unsigned int opt_highest_port = 65535;
static void cb_highest_port(const char *arg)
-{ highest_port = parsenum(arg, 65535); }
+{ opt_highest_port = parsenum(arg, 65535); }
-int wait_secs = -1;
+int opt_wait_secs = -1;
static void cb_wait_secs(const char *arg)
-{ wait_secs = (int)parsenum(arg, 0); }
+{ opt_wait_secs = (int)parsenum(arg, 0); }
-int want_hexdump = 0;
-static void cb_hexdump(const char *arg _unused_) { want_hexdump = 1; }
+int opt_want_hexdump = 0;
+static void cb_hexdump(const char *arg _unused_) { opt_want_hexdump = 1; }
/* --- */
parse_sub_cmdline(argc, argv);
/* start syslogging as early as possible */
- if (want_syslog) openlog("darkstat", LOG_NDELAY | LOG_PID, LOG_DAEMON);
+ if (opt_want_syslog) openlog("darkstat", LOG_NDELAY | LOG_PID, LOG_DAEMON);
/* some default values */
- if (chroot_dir == NULL) chroot_dir = CHROOT_DIR;
- if (privdrop_user == NULL) privdrop_user = PRIVDROP_USER;
+ if (opt_chroot_dir == NULL) opt_chroot_dir = CHROOT_DIR;
+ if (opt_privdrop_user == NULL) opt_privdrop_user = PRIVDROP_USER;
/* sanity check args */
- if ((interface == NULL) && (capfile == NULL))
+ if ((opt_interface == NULL) && (opt_capfile == NULL))
errx(1, "must specify either interface (-i) or capture file (-r)");
- if ((interface != NULL) && (capfile != NULL))
+ if ((opt_interface != NULL) && (opt_capfile != NULL))
errx(1, "can't specify both interface (-i) and capture file (-r)");
- if ((hosts_max != 0) && (hosts_keep >= hosts_max)) {
- hosts_keep = hosts_max / 2;
+ if ((opt_hosts_max != 0) && (opt_hosts_keep >= opt_hosts_max)) {
+ opt_hosts_keep = opt_hosts_max / 2;
warnx("reducing --hosts-keep to %u, to be under --hosts-max (%u)",
- hosts_keep, hosts_max);
+ opt_hosts_keep, opt_hosts_max);
}
verbosef("max %u hosts, cutting down to %u when exceeded",
- hosts_max, hosts_keep);
+ opt_hosts_max, opt_hosts_keep);
- if ((ports_max != 0) && (ports_keep >= ports_max)) {
- ports_keep = ports_max / 2;
+ if ((opt_ports_max != 0) && (opt_ports_keep >= opt_ports_max)) {
+ opt_ports_keep = opt_ports_max / 2;
warnx("reducing --ports-keep to %u, to be under --ports-max (%u)",
- ports_keep, ports_max);
+ opt_ports_keep, opt_ports_max);
}
verbosef("max %u ports per host, cutting down to %u when exceeded",
- ports_max, ports_keep);
+ opt_ports_max, opt_ports_keep);
- if (want_hexdump && !want_verbose) {
- want_verbose = 1;
+ if (opt_want_hexdump && !opt_want_verbose) {
+ opt_want_verbose = 1;
verbosef("--hexdump implies --verbose");
}
- if (want_hexdump && want_daemonize) {
- want_daemonize = 0;
+ if (opt_want_hexdump && opt_want_daemonize) {
+ opt_want_daemonize = 0;
verbosef("--hexdump implies --no-daemon");
}
}
{
graph_init();
hosts_db_init();
- cap_from_file(capfile, filter);
+ cap_from_file(opt_capfile, opt_filter);
cap_stop();
if (export_fn != NULL) db_export(export_fn);
hosts_db_free();
graph_free();
- verbosef("Total packets: %qu, bytes: %qu", total_packets, total_bytes);
+ verbosef("Total packets: %qu, bytes: %qu",
+ acct_total_packets, acct_total_bytes);
}
/* --- Program body --- */
test_64order();
parse_cmdline(argc-1, argv+1);
- if (capfile) {
+ if (opt_capfile) {
/*
* This is very different from a regular run against a network
* interface.
/* must verbosef() before first fork to init lock */
verbosef("starting up");
- if (pid_fn) pidfile_create(chroot_dir, pid_fn, privdrop_user);
+ if (pid_fn) pidfile_create(opt_chroot_dir, pid_fn, opt_privdrop_user);
- if (want_daemonize) {
+ if (opt_want_daemonize) {
verbosef("daemonizing to run in the background!");
daemonize_start();
verbosef("I am the main process");
if (pid_fn) pidfile_write_close();
/* do this first as it forks - minimize memory use */
- if (want_dns) dns_init(privdrop_user);
- cap_init(interface, filter, want_promisc); /* needs root */
- http_init(base, bindaddr, bindport, /*maxconn=*/-1);
+ if (opt_want_dns) dns_init(opt_privdrop_user);
+ cap_init(opt_interface, opt_filter, opt_want_promisc); /* needs root */
+ http_init(opt_base, opt_bindaddr, opt_bindport, /*maxconn=*/-1);
ncache_init(); /* must do before chroot() */
- privdrop(chroot_dir, privdrop_user);
+ privdrop(opt_chroot_dir, opt_privdrop_user);
/* Don't need root privs for these: */
now = time(NULL);
graph_init();
hosts_db_init();
if (import_fn != NULL) db_import(import_fn);
- localip_init(interface);
+ localip_init(opt_interface);
if (signal(SIGTERM, sig_shutdown) == SIG_ERR)
errx(1, "signal(SIGTERM) failed");
verbosef("shutting down");
verbosef("pcap stats: %u packets received, %u packets dropped",
- pkts_recv, pkts_drop);
+ cap_pkts_recv, cap_pkts_drop);
http_stop();
cap_stop();
dns_stop();
* - PACKAGE_STRING
*/
#include "config.h"
+#include "opt.h"
#ifdef __GNUC__
# define _unused_ __attribute__((__unused__))
#include <netinet/tcp.h> /* struct tcphdr */
#include <netinet/udp.h> /* struct udphdr */
-extern int want_pppoe;
-
static void decode_ether(u_char *, const struct pcap_pkthdr *,
const u_char *);
static void decode_loop(u_char *, const struct pcap_pkthdr *,
switch (type) {
case ETHERTYPE_IP:
case ETHERTYPE_IPV6:
- if (!want_pppoe) {
+ if (!opt_want_pppoe) {
decode_ip(pdata + ETHER_HDR_LEN,
pheader->caplen - ETHER_HDR_LEN, &sm);
acct_for(&sm);
/* known protocol, don't complain about it. */
break;
case ETHERTYPE_PPPOE:
- if (want_pppoe)
+ if (opt_want_pppoe)
decode_pppoe_real(pdata + ETHER_HDR_LEN,
pheader->caplen - ETHER_HDR_LEN, &sm);
else
va_list va;
va_start(va, format);
- if (want_syslog)
+ if (opt_want_syslog)
to_syslog("ERROR: ", 1, format, va);
else {
fprintf(stderr, "%5d: error: ", (int)getpid());
va_list va;
va_start(va, format);
- if (want_syslog)
+ if (opt_want_syslog)
to_syslog("ERROR: ", 0, format, va);
else {
fprintf(stderr, "%5d: error: ", (int)getpid());
va_list va;
va_start(va, format);
- if (want_syslog)
+ if (opt_want_syslog)
to_syslog("WARNING: ", 1, format, va);
else {
fprintf(stderr, "%5d: warning: ", (int)getpid());
va_list va;
va_start(va, format);
- if (want_syslog)
+ if (opt_want_syslog)
to_syslog("WARNING: ", 0, format, va);
else {
fprintf(stderr, "%5d: warning: ", (int)getpid());
}
}
-int want_verbose = 0, want_syslog = 0;
-
void
verbosef(const char *format, ...)
{
va_list va;
- if (!want_verbose) return;
+ if (!opt_want_verbose) return;
va_start(va, format);
- if (want_syslog)
+ if (opt_want_syslog)
to_syslog(NULL, 0, format, va);
else {
lock();
void warn(const char *format, ...) _printflike_(1, 2);
void warnx(const char *format, ...) _printflike_(1, 2);
-extern int want_verbose, want_syslog;
void verbosef(const char *format, ...) _printflike_(1, 2);
void dverbosef(const char *format _unused_, ...);
#define GRAPH_WIDTH "320"
#define GRAPH_HEIGHT "200"
-extern const char *interface;
-
struct graph {
uint64_t *in, *out;
unsigned int offset; /* i.e. seconds start at 0, days start at 1 */
char start_when[100];
buf = str_make();
- html_open(buf, "Graphs", interface, /*want_graph_js=*/1);
+ html_open(buf, "Graphs", opt_interface, /*want_graph_js=*/1);
str_append(buf, "<p>\n");
str_append(buf, "<b>Running for</b> <span id=\"rf\">");
"(<span id=\"pc\">%'u</span> <b>captured,</b> "
"<span id=\"pd\">%'u</span> <b>dropped)</b><br>\n"
"</p>\n",
- total_bytes,
- total_packets,
- pkts_recv, pkts_drop);
+ acct_total_bytes,
+ acct_total_packets,
+ cap_pkts_recv, cap_pkts_drop);
str_append(buf,
"<div id=\"graphs\">\n"
struct str *buf = str_make(), *rf;
str_appendf(buf, "<graphs tp=\"%qu\" tb=\"%qu\" pc=\"%u\" pd=\"%u\" rf=\"",
- total_packets, total_bytes, pkts_recv, pkts_drop);
+ acct_total_packets, acct_total_bytes, cap_pkts_recv, cap_pkts_drop);
rf = length_of_time(now - start_time);
str_appendstr(buf, rf);
str_free(rf);
#include "hosts_db.h"
#include "db.h"
#include "html.h"
-#include "http.h" /* for base_url */
+#include "http.h" /* for http_base_url */
#include "ncache.h"
#include "now.h"
#include "str.h"
#include <string.h> /* memset(), strcmp() */
#include <unistd.h>
-extern int want_lastseen;
-int show_mac_addrs = 0;
-extern const char *interface;
+int hosts_db_show_macs = 0;
/* FIXME: specify somewhere more sane/tunable */
#define MAX_ENTRIES 30 /* in an HTML table rendered from a hashtable */
"<tr>\n"
" <th>IP</th>\n"
" <th>Hostname</th>\n");
- if (show_mac_addrs) str_append(buf,
+ if (hosts_db_show_macs) str_append(buf,
" <th>MAC Address</th>\n");
str_append(buf,
" <th><a href=\"?sort=in\">In</a></th>\n"
" <th><a href=\"?sort=out\">Out</a></th>\n"
" <th><a href=\"?sort=total\">Total</a></th>\n");
- if (want_lastseen) str_append(buf,
+ if (opt_want_lastseen) str_append(buf,
" <th><a href=\"?sort=lastseen\">Last seen</a></th>\n");
str_append(buf,
"</tr>\n");
" <td><a href=\"%shosts/%s/\">%s</a></td>\n"
" <td>%s</td>\n",
css_class,
- base_url, ip, ip,
+ http_base_url, ip, ip,
(b->u.host.dns == NULL) ? "" : b->u.host.dns);
- if (show_mac_addrs)
+ if (hosts_db_show_macs)
str_appendf(buf,
" <td><tt>%x:%x:%x:%x:%x:%x</tt></td>\n",
b->u.host.mac_addr[0],
" <td class=\"num\">%'qu</td>\n",
b->in, b->out, b->total);
- if (want_lastseen) {
+ if (opt_want_lastseen) {
time_t last_t = b->u.host.last_seen;
struct str *lastseen = NULL;
hosts_db_init(void)
{
assert(hosts_db == NULL);
- hosts_db = hashtable_make(HOST_BITS, hosts_max, hosts_keep,
+ hosts_db = hashtable_make(HOST_BITS, opt_hosts_max, opt_hosts_keep,
hash_func_host, free_func_host, key_func_host, find_func_host,
make_func_host, format_cols_host, format_row_host);
}
struct host *h = &host->u.host;
assert(h != NULL);
if (h->ports_tcp == NULL)
- h->ports_tcp = hashtable_make(PORT_BITS, ports_max, ports_keep,
+ h->ports_tcp = hashtable_make(PORT_BITS, opt_ports_max, opt_ports_keep,
hash_func_short, free_func_simple, key_func_port_tcp,
find_func_port_tcp, make_func_port_tcp,
format_cols_port_tcp, format_row_port_tcp);
struct host *h = &host->u.host;
assert(h != NULL);
if (h->ports_udp == NULL)
- h->ports_udp = hashtable_make(PORT_BITS, ports_max, ports_keep,
+ h->ports_udp = hashtable_make(PORT_BITS, opt_ports_max, opt_ports_keep,
hash_func_short, free_func_simple, key_func_port_udp,
find_func_port_udp, make_func_port_udp,
format_cols_port_udp, format_row_port_udp);
#define NEXT "next page >>>"
#define FULL "full table"
- html_open(buf, "Hosts", interface, /*want_graph_js=*/0);
+ html_open(buf, "Hosts", opt_interface, /*want_graph_js=*/0);
format_table(buf, hosts_db, start, sort, full);
/* <prev | full | stats | next> */
/* Overview. */
buf = str_make();
- html_open(buf, ip, interface, /*want_graph_js=*/0);
+ html_open(buf, ip, opt_interface, /*want_graph_js=*/0);
if (strcmp(ip, canonical) != 0)
str_appendf(buf, "(canonically <b>%s</b>)\n", canonical);
str_appendf(buf,
if (h->u.host.dns == NULL)
dns_queue(&(h->u.host.addr));
- if (show_mac_addrs)
+ if (hosts_db_show_macs)
str_appendf(buf,
"<b>MAC Address:</b> "
"<tt>%x:%x:%x:%x:%x:%x</tt><br>\n",
enum sort_dir { IN, OUT, TOTAL, LASTSEEN };
-extern int show_mac_addrs;
-
-/*
- * Table reduction - when the number of entries is about to exceed <max>, we
- * reduce the table to the top <keep> entries.
- */
-extern unsigned int hosts_max, hosts_keep, ports_max, ports_keep;
+extern int hosts_db_show_macs;
void hosts_db_init(void);
void hosts_db_reduce(void);
#include "config.h" /* for PACKAGE_STRING, PACKAGE_URL */
#include "str.h"
#include "html.h"
-#include "http.h" /* for base_url */
+#include "http.h" /* for http_base_url */
void html_open(struct str *buf, const char *title, const char *interface,
const int want_graph_js)
"<meta name=\"generator\" content=\"" PACKAGE_STRING "\">\n"
"<meta name=\"robots\" content=\"noindex, noarchive\">\n"
"<link rel=\"stylesheet\" href=\"%sstyle.css\" type=\"text/css\">\n"
- , title, interface, base_url);
+ , title, interface, http_base_url);
if (want_graph_js)
str_appendf(buf,
"<script src=\"%sgraph.js\" type=\"text/javascript\"></script>\n"
- , base_url);
+ , http_base_url);
str_appendf(buf,
"</head>\n"
"</div>\n"
"<div class=\"content\">\n"
"<h2 class=\"pageheader\">%s</h2>\n"
- , base_url, base_url, title);
+ , http_base_url, http_base_url, title);
}
void html_close(struct str *buf)
#include <unistd.h>
#include <zlib.h>
-char *base_url = NULL;
+char *http_base_url = NULL;
static const char mime_type_xml[] = "text/xml";
static const char mime_type_html[] = "text/html; charset=us-ascii";
/* make relative (or fail) */
decoded_url = safe_url;
- if (!str_starts_with(decoded_url, base_url))
+ if (!str_starts_with(decoded_url, http_base_url))
{
default_reply(conn, 404, "Not Found",
"The page you requested could not be found.");
free(decoded_url);
return;
}
- safe_url = decoded_url + strlen(base_url) - 1;
+ safe_url = decoded_url + strlen(http_base_url) - 1;
if (strcmp(safe_url, "/") == 0) {
struct str *buf = html_front_page();
size_t urllen;
if (url == NULL) {
- base_url = strdup("/");
+ http_base_url = strdup("/");
return;
}
free(slashed_url);
if (safe_url == NULL) {
verbosef("invalid base \"%s\", ignored", url);
- base_url = strdup("/"); /* set to default */
+ http_base_url = strdup("/"); /* set to default */
return;
}
else
- base_url = safe_url;
+ http_base_url = safe_url;
}
/* Use getaddrinfo to figure out what type of socket to create and
(ai->ai_family == AF_INET6) ? "[" : "",
ipaddr,
(ai->ai_family == AF_INET6) ? "]" : "",
- bindport, base_url);
+ bindport, http_base_url);
freeaddrinfo(ai);
}
void http_stop(void) {
- free(base_url);
+ free(http_base_url);
close(sockin);
}
#include <sys/select.h>
#include <netinet/in.h>
-extern char *base_url;
+extern char *http_base_url;
void http_init(const char *base, const char * bindaddr,
const unsigned short bindport, const int max_conn);
--- /dev/null
+/* darkstat 3
+ * copyright (c) 2001-2011 Emil Mikulic.
+ *
+ * opt.h: global options
+ */
+
+/*
+ * Capture options.
+ */
+extern int opt_want_pppoe;
+extern int opt_want_macs;
+extern int opt_want_hexdump;
+extern int opt_want_snaplen;
+extern int opt_wait_secs;
+
+/*
+ * Error/logging options.
+ */
+extern int opt_want_verbose;
+extern int opt_want_syslog;
+
+/*
+ * Accounting options.
+ */
+extern unsigned int opt_highest_port;
+
+/*
+ * Hosts table reduction - when the number of entries is about to exceed
+ * <max>, we reduce the table to the top <keep> entries.
+ */
+extern unsigned int opt_hosts_max;
+extern unsigned int opt_hosts_keep;
+extern unsigned int opt_ports_max;
+extern unsigned int opt_ports_keep;
+
+/*
+ * Hosts output options.
+ */
+extern int opt_want_lastseen;
+extern const char *opt_interface;
+
+