3 IPTraffic monitoring extensions for Tomato
4 Copyright (C) 2011-2012 Augusto Bott
7 Copyright (C) 2006-2009 Jonathan Zarate
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
24 void iptraffic_conntrack_init();
26 typedef struct _Node
{
27 char ipaddr
[INET_ADDRSTRLEN
];
28 unsigned int tcp_conn
;
29 unsigned int udp_conn
;
31 TREE_ENTRY(_Node
) linkage
;
34 typedef TREE_HEAD(_Tree
, _Node
) Tree
;
36 TREE_DEFINE(_Node
, linkage
);
38 Node
*Node_new(char *ipaddr
) {
40 if ((self
= malloc(sizeof(Node
))) != NULL
) {
41 memset(self
, 0, sizeof(Node
));
42 strncpy(self
->ipaddr
, ipaddr
, INET_ADDRSTRLEN
);
45 _dprintf("%s: new node ip=%s, sizeof(Node)=%d (bytes)\n", __FUNCTION__
, self
->ipaddr
, sizeof(Node
));
50 int Node_compare(Node
*lhs
, Node
*rhs
) {
51 return strncmp(lhs
->ipaddr
, rhs
->ipaddr
, INET_ADDRSTRLEN
);
54 Tree tree
= TREE_INITIALIZER(Node_compare
);
56 void Node_housekeeping(Node
*self
, void *info
) {
62 void Node_print(Node *self, FILE *stream) {
63 fprintf(stream, "%s/%d/%d", self->ipaddr, self->tcp_conn, self->udp_conn);
66 void Node_printer(Node *self, void *stream) {
67 Node_print(self, (FILE *)stream);
68 fprintf((FILE *)stream, " ");
71 void Tree_info(void) {
73 TREE_FORWARD_APPLY(&tree, _Node, linkage, Node_printer, stdout);
75 _dprintf("Tree depth = %d\n", TREE_DEPTH(&tree, linkage));