f2f389af972b57d59cd53af75b09ab6f7c22bdb1
[darkstat-debian] / hosts_db.h
1 /* darkstat 3
2 * copyright (c) 2001-2011 Emil Mikulic.
3 *
4 * hosts_db.h: database of hosts, ports, protocols.
5 *
6 * You may use, modify and redistribute this file under the terms of the
7 * GNU General Public License version 2. (see COPYING.GPL)
8 */
9 #ifndef __DARKSTAT_HOSTS_DB_H
10 #define __DARKSTAT_HOSTS_DB_H
11
12 #include <sys/types.h> /* for time_t and uint64_t (esp on FreeBSD) */
13
14 #include "addr.h"
15
16 struct hashtable;
17
18 struct host {
19 struct addr addr;
20 char *dns;
21 uint8_t mac_addr[6];
22 time_t lastseen;
23 struct hashtable *ports_tcp, *ports_udp, *ip_protos;
24 };
25
26 struct port_tcp {
27 uint16_t port;
28 uint64_t syn;
29 };
30
31 struct port_udp {
32 uint16_t port;
33 };
34
35 struct ip_proto {
36 uint8_t proto;
37 };
38
39 struct bucket {
40 struct bucket *next;
41 uint64_t in, out, total;
42 union {
43 struct host host;
44 struct port_tcp port_tcp;
45 struct port_udp port_udp;
46 struct ip_proto ip_proto;
47 } u;
48 };
49
50 enum sort_dir { IN, OUT, TOTAL, LASTSEEN };
51
52 extern int hosts_db_show_macs;
53
54 void hosts_db_init(void);
55 void hosts_db_reduce(void);
56 void hosts_db_reset(void);
57 void hosts_db_free(void);
58 int hosts_db_import(const int fd);
59 int hosts_db_export(const int fd);
60
61 struct bucket *host_find(const struct addr *const a); /* can return NULL */
62 struct bucket *host_get(const struct addr *const a);
63 struct bucket *host_get_port_tcp(struct bucket *host, const uint16_t port);
64 struct bucket *host_get_port_udp(struct bucket *host, const uint16_t port);
65 struct bucket *host_get_ip_proto(struct bucket *host, const uint8_t proto);
66
67 /* Web pages. */
68 struct str *html_hosts(const char *uri, const char *query);
69
70 /* From hosts_sort */
71 void qsort_buckets(const struct bucket **a, size_t n,
72 size_t left, size_t right, const enum sort_dir d);
73
74 #endif /* __DARKSTAT_HOSTS_DB_H */
75 /* vim:set ts=3 sw=3 tw=78 expandtab: */