2 * copyright (c) 2001-2014 Emil Mikulic.
4 * hosts_db.h: database of hosts, ports, protocols.
6 * You may use, modify and redistribute this file under the terms of the
7 * GNU General Public License version 2. (see COPYING.GPL)
9 #ifndef __DARKSTAT_HOSTS_DB_H
10 #define __DARKSTAT_HOSTS_DB_H
12 #include <sys/types.h> /* for uint64_t */
22 /* last_seen_mono is converted to/from time_t in export/import.
23 * It can be negative (due to machine reboots).
25 int64_t last_seen_mono
;
26 struct hashtable
*ports_tcp
;
27 struct hashtable
*ports_tcp_remote
;
28 struct hashtable
*ports_udp
;
29 struct hashtable
*ports_udp_remote
;
30 struct hashtable
*ip_protos
;
48 uint64_t in
, out
, total
;
51 struct port_tcp port_tcp
;
52 struct port_udp port_udp
;
53 struct ip_proto ip_proto
;
57 enum sort_dir
{ IN
, OUT
, TOTAL
, LASTSEEN
};
59 extern int hosts_db_show_macs
;
61 void hosts_db_init(void);
62 void hosts_db_reduce(void);
63 void hosts_db_reset(void);
64 void hosts_db_free(void);
65 int hosts_db_import(const int fd
);
66 int hosts_db_export(const int fd
);
68 struct bucket
*host_find(const struct addr
*const a
); /* can return NULL */
69 struct bucket
*host_get(const struct addr
*const a
);
70 struct bucket
*host_get_port_tcp(struct bucket
*host
, const uint16_t port
);
71 struct bucket
*host_get_port_tcp_remote(struct bucket
*host
,
73 struct bucket
*host_get_port_udp(struct bucket
*host
, const uint16_t port
);
74 struct bucket
*host_get_port_udp_remote(struct bucket
*host
,
76 struct bucket
*host_get_ip_proto(struct bucket
*host
, const uint8_t proto
);
79 struct str
*html_hosts(const char *uri
, const char *query
);
82 void qsort_buckets(const struct bucket
**a
, size_t n
,
83 size_t left
, size_t right
, const enum sort_dir d
);
85 #endif /* __DARKSTAT_HOSTS_DB_H */
86 /* vim:set ts=3 sw=3 tw=78 expandtab: */