-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.c
198 lines (170 loc) · 6.22 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* This file is a part of groinc
*
* Copyright (C) 2006, 2007 Sarzyniec Luc <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* see the COPYING file for more informations */
#include "display.h"
#include "globals_display.h"
#include "globals_report.h"
#include "globals_filter.h"
#include "tools/compiler.h"
#include "network/headers.h"
#include "network/printers.h"
#include "prints.h"
#include <sys/time.h>
void display_packet(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
struct linked_list *ptr = list_display_packet;
if (likely(ptr->value))
{
while (ptr)
{
(ptr->value->u.dsp_pkt->func_dsp_pkt)(fd,datalink_layerph,network_layerph,transport_layerph,datagram);
ptr = ptr->next;
print_newline(fd);
}
}
else
{
dsp_pkt_simple(fd,datalink_layerph,network_layerph,transport_layerph,datagram);
print_newline(fd);
dsp_pkt_data(fd,datalink_layerph,network_layerph,transport_layerph,datagram);
print_newline(fd);
}
print_separator(fd);
print_newline(fd);
}
void display_report(int fd)
{
struct linked_list *ptr = list_display_report;
if (likely(ptr->value))
{
print_newline(fd);
while (ptr)
{
(ptr->value->u.dsp_rpt->func_dsp_rpt)(fd,ptr->value->u.dsp_rpt->val);
ptr = ptr->next;
print_newline(fd);
}
}
else
{
/*
dsp_rpt_countpacketstot(fd,val);
dsp_rpt_countpacketsfiltred(fd,val);
print_newline(fd);
dsp_rpt_timetot(fd,val);
*/
print_newline(fd);
dsp_rpt_default(fd,0);
print_newline(fd);
}
print_newline(fd);
}
void dsp_pkt_packets(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_packetnb(fd,datagram->len);
}
void dsp_pkt_dlproto(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_datalink_layer_proto(fd,datalink_layerph);
}
__inline void dsp_pkt_nlproto(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_network_layer_proto(fd,datalink_layerph,network_layerph);
}
void dsp_pkt_tlproto(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_transport_layer_proto(fd,network_layerph,transport_layerph);
}
void dsp_pkt_simple(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_proto_simple(fd,datalink_layerph,network_layerph,transport_layerph);
print_simple(fd,datalink_layerph,network_layerph,transport_layerph);
}
void dsp_pkt_header(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_datalink_layer(fd,datalink_layerph);
print_network_layer(fd,network_layerph);
print_transport_layer(fd,transport_layerph);
}
void dsp_pkt_data(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_data(datafd,datagram);
}
void dsp_pkt_hexa(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_protoproto(fd,datalink_layerph);
print_hexa(fd,datalink_layerph->header,datalink_layerph->len);
print_newline(fd);
print_ethproto(fd,network_layerph);
print_hexa(fd,network_layerph->header,network_layerph->len);
print_newline(fd);
print_ipproto(fd,transport_layerph);
print_hexa(fd,transport_layerph->header,transport_layerph->len);
print_newline(fd);
print_newline(fd);
print_packetnb(fd,(datagram->totlen - datagram->len));
print_hexa(fd,(datagram->data + datagram->len),(datagram->totlen - datagram->len));
}
void dsp_pkt_allpackets(int fd, struct protocol_header *datalink_layerph, struct protocol_header *network_layerph, struct protocol_header *transport_layerph, struct data *datagram)
{
print_packetnb(fd,datagram->len);
}
void dsp_rpt_timetot(int fd, __u8 *val)
{
struct timeval timecur,*timesta;
time_t totsec;
suseconds_t totusec;
timesta = (struct timeval *) val;
gettimeofday(&timecur,0);
totsec = (timecur.tv_sec - timesta->tv_sec);
if ((totusec = (timecur.tv_usec - timesta->tv_usec)) < 0)
{
totsec--;
totusec = (1000000 - timesta->tv_usec) + timecur.tv_usec;
}
print_format(fd, "[Time total: %hds %hdms]",totsec,(totusec / 1000));
}
#define DSP_RPT_COUNT_PACKETS_CAST(V) \
__extension__ \
({ \
*((unsigned int *) *((unsigned int *) val)); \
})
void dsp_rpt_default(int fd, __u8 *val)
{
struct timeval timecur;
time_t totsec;
suseconds_t totusec;
gettimeofday(&timecur,0);
totsec = (timecur.tv_sec - default_report.timestart.tv_sec);
if ((totusec = (timecur.tv_usec - default_report.timestart.tv_usec)) < 0)
{
totsec--;
totusec = (1000000 - default_report.timestart.tv_usec) + timecur.tv_usec;
}
print_format(fd,"Time - [total %hds %hdms]\n"
"Packets - [total %hu packets] [filtred %hu packets]",
totsec,(totusec / 1000),default_report.countpacketstot,default_report.countpacketsfiltred);
}
void dsp_rpt_countpacketstot(int fd, __u8 *val)
{
print_format(fd,"[Packets total : %hu packets]",DSP_RPT_COUNT_PACKETS_CAST(val));
}
void dsp_rpt_countpacketsfiltred(int fd, __u8 *val)
{
print_format(fd,"[Packets filtred : %hu packets]",DSP_RPT_COUNT_PACKETS_CAST(val));
}