dnscrypto-proxy: Update to release 1.3.0
[tomato.git] / release / src / router / httpd / iptraffic.h
blobc3f11e8819456b1ce7c268aa73ba71398adc9a2d
1 /*
3 IPTraffic monitoring extensions for Tomato
4 Copyright (C) 2011-2012 Augusto Bott
6 Tomato Firmware
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.
22 #include <tree.h>
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;
32 } Node;
34 typedef TREE_HEAD(_Tree, _Node) Tree;
36 TREE_DEFINE(_Node, linkage);
38 Node *Node_new(char *ipaddr) {
39 Node *self;
40 if ((self = malloc(sizeof(Node))) != NULL) {
41 memset(self, 0, sizeof(Node));
42 strncpy(self->ipaddr, ipaddr, INET_ADDRSTRLEN);
43 self->tcp_conn = 0;
44 self->udp_conn = 0;
45 _dprintf("%s: new node ip=%s, sizeof(Node)=%d (bytes)\n", __FUNCTION__, self->ipaddr, sizeof(Node));
47 return self;
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) {
57 free(self);
60 // DEBUG
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) {
72 _dprintf("Tree = ");
73 TREE_FORWARD_APPLY(&tree, _Node, linkage, Node_printer, stdout);
74 _dprintf("\n");
75 _dprintf("Tree depth = %d\n", TREE_DEPTH(&tree, linkage));