capt_get_packet(): check for key press only every 20ms
[iptraf-ng.git] / src / tcptable.h
blob6ee90adc39163e11294f2a0e9d8dc15db0df3499
1 #ifndef IPTRAF_NG_TCPTABLE_H
2 #define IPTRAF_NG_TCPTABLE_H
4 /***
6 tcptable.h -- table manipulation for the statistics display.
8 ***/
10 #include "packet.h"
11 #include "rate.h"
14 * max() macros that also do
15 * strict type-checking.. See the
16 * "unnecessary" pointer comparison.
18 #define max(x, y) ({ \
19 typeof(x) _max1 = (x); \
20 typeof(y) _max2 = (y); \
21 (void) (&_max1 == &_max2); \
22 _max1 > _max2 ? _max1 : _max2; })
24 #define FLAG_SYN 1
25 #define FLAG_RST 2
26 #define FLAG_PSH 4
27 #define FLAG_ACK 8
28 #define FLAG_URG 16
30 #define CLOSED 64
32 #define ENTRIES_IN_HASH_TABLE 1543
34 struct tcptableent {
35 struct sockaddr_storage saddr;
36 struct sockaddr_storage daddr;
37 char s_fqdn[45]; /* fully-qualified domain names */
38 char d_fqdn[45];
39 int s_fstat;
40 int d_fstat;
41 char smacaddr[18];
42 char s_sname[11]; /* Service names, maxlen=10 */
43 char d_sname[11];
44 unsigned int protocol;
45 unsigned long pcount; /* packet count */
46 unsigned long bcount; /* byte count */
47 unsigned int stat; /* TCP flags */
48 unsigned int win;
49 unsigned int psize;
50 unsigned long finack;
51 int partial;
52 int finsent;
53 char ifname[IFNAMSIZ];
54 unsigned int index;
55 int reused;
56 int timedout;
57 int inclosed;
58 int half_bracket;
59 unsigned long spanbr;
60 struct rate rate;
61 time_t lastupdate;
62 time_t conn_starttime;
63 struct tcp_hashentry *hash_node;
64 struct tcptableent *oth_connection; /* the other half of the connection */
65 struct tcptableent *prev_entry;
66 struct tcptableent *next_entry;
69 struct closedlist {
70 struct tcptableent *closedentry;
71 struct tcptableent *pair;
72 struct closedlist *next_entry;
75 struct tcp_hashentry {
76 unsigned int index;
77 unsigned int hp; /* index position in bucket array */
78 struct tcptableent *tcpnode;
79 struct tcp_hashentry *prev_entry;
80 struct tcp_hashentry *next_entry;
83 struct tcptable {
84 struct tcp_hashentry *hash_table[ENTRIES_IN_HASH_TABLE];
85 struct tcp_hashentry *hash_tails[ENTRIES_IN_HASH_TABLE];
86 struct tcptableent *head;
87 struct tcptableent *tail;
88 struct closedlist *closedentries;
89 struct closedlist *closedtail;
90 struct tcptableent *firstvisible;
91 struct tcptableent *lastvisible;
92 struct tcptableent *barptr;
93 unsigned int lastpos;
94 unsigned int count;
95 unsigned int bmaxy; /* number of lines of the border window */
96 unsigned int imaxy; /* number of lines inside the border */
97 int ifnamew; /* interface name width to display */
98 int mode;
100 WINDOW *tcpscreen;
101 PANEL *tcppanel;
102 WINDOW *borderwin;
103 PANEL *borderpanel;
104 WINDOW *statwin;
105 PANEL *statpanel;
108 void show_stats(WINDOW *win, unsigned long long total);
110 void init_tcp_table(struct tcptable *table);
112 struct tcptableent *addentry(struct tcptable *table,
113 struct sockaddr_storage *saddr,
114 struct sockaddr_storage *daddr,
115 int protocol, char *ifname,
116 int *rev_lookup, int rvnamedon);
118 void mark_timeouted_entries(struct tcptable *table, int logging, FILE *logfile);
120 struct tcptableent *in_table(struct tcptable *table,
121 struct sockaddr_storage *saddr,
122 struct sockaddr_storage *daddr,
123 char *ifname);
125 void updateentry(struct tcptable *table, struct pkt_hdr *pkt,
126 struct tcptableent *tableentry, struct tcphdr *transpacket,
127 unsigned int bcount, int *revlook, int rvnfd, int logging,
128 FILE *logfile);
130 void addtoclosedlist(struct tcptable *table, struct tcptableent *tableentry);
132 void clearaddr(struct tcptable *table, struct tcptableent *tableentry);
134 void printentry(struct tcptable *table, struct tcptableent *tableentry);
136 void refreshtcpwin(struct tcptable *table);
138 void destroytcptable(struct tcptable *table);
140 void flushclosedentries(struct tcptable *table);
142 void write_timeout_log(int logging, FILE *logfile, struct tcptableent *tcpnode);
144 void writetcplog(int logging, FILE *fd, struct tcptableent *entry,
145 unsigned int pktlen, char *message);
147 void write_tcp_unclosed(int logging, FILE *fd, struct tcptable *table);
149 #endif /* IPTRAF_NG_TCPTABLE_H */