|
...
|
...
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
#include <stdio.h>
|
|
2
|
2
|
#include <stdlib.h>
|
|
3
|
3
|
#include <stdint.h>
|
|
|
4
|
+#include <inttypes.h>
|
|
4
|
5
|
#include <string.h>
|
|
5
|
6
|
#include <pcap.h>
|
|
6
|
7
|
#include <time.h>
|
|
...
|
...
|
@@ -36,11 +37,17 @@
|
|
36
|
37
|
static char st_device[MAX_SIZE]="eth0";//By default launch on eth0
|
|
37
|
38
|
static char st_filter[MAX_FILTER_SIZE]="ip";//By filter only on IP datagram
|
|
38
|
39
|
static char st_file_prefix[MAX_SIZE]="";//Will be time of day
|
|
39
|
|
-static int st_packet_num = 0;
|
|
|
40
|
+static uint64_t st_packet_num = 0;
|
|
40
|
41
|
//~ static pcap_t *st_hdl_out_pcap = NULL;
|
|
41
|
42
|
//~ static pcap_dumper_t *st_hdl_out_pcapdumper = NULL;
|
|
42
|
43
|
static FILE *st_hdl_out_mypcap = NULL;
|
|
43
|
44
|
|
|
|
45
|
+static void print_capture_progress(void)
|
|
|
46
|
+{
|
|
|
47
|
+ printf("\r\033[KPackets captured: %" PRIu64, st_packet_num);
|
|
|
48
|
+ fflush(stdout);
|
|
|
49
|
+}
|
|
|
50
|
+
|
|
44
|
51
|
void usage()
|
|
45
|
52
|
{
|
|
46
|
53
|
printf( "%s (%s) %s\nDescription :\n\t%s\nUsage :\n\t%s <incap>\n", APP_NAME, APP_VERSION, APP_DATE, APP_DESCRIPTION, APP_NAME );
|
|
...
|
...
|
@@ -56,12 +63,17 @@ void pcap_loop_cb(u_char *useless,const struct pcap_pkthdr* header,const u_char*
|
|
56
|
63
|
if (header == NULL || packet == NULL) {
|
|
57
|
64
|
return;
|
|
58
|
65
|
}
|
|
|
66
|
+ ++st_packet_num;
|
|
|
67
|
+ uint64_t report_interval = st_packet_num <= 10 ? 1 :
|
|
|
68
|
+ (st_packet_num <= 100 ? 10 : (st_packet_num <= 1000 ? 100 : 1000));
|
|
|
69
|
+ if (st_packet_num % report_interval == 0) {
|
|
|
70
|
+ print_capture_progress();
|
|
|
71
|
+ }
|
|
59
|
72
|
|
|
60
|
73
|
//Inode <-> Process Update
|
|
61
|
74
|
cnx_inode_refresh();
|
|
62
|
75
|
reread_mapping();
|
|
63
|
76
|
|
|
64
|
|
- ++st_packet_num;//update packet counter
|
|
65
|
77
|
if( NULL != st_hdl_out_mypcap ) {
|
|
66
|
78
|
mypcap_dump(st_hdl_out_mypcap,
|
|
67
|
79
|
(const struct pcap_pkthdr*)header,
|
|
...
|
...
|
@@ -112,7 +124,8 @@ void pcap_loop_cb(u_char *useless,const struct pcap_pkthdr* header,const u_char*
|
|
112
|
124
|
//Dump into its own file
|
|
113
|
125
|
|
|
114
|
126
|
//~ printf("\n\t\t%s FOR\n", result->data.cmdline);
|
|
115
|
|
- printf("#%i %s\n", st_packet_num, result->data.cmdline);
|
|
|
127
|
+ printf("\r\033[K#%" PRIu64 " %s\n", st_packet_num, result->data.cmdline);
|
|
|
128
|
+ print_capture_progress();
|
|
116
|
129
|
//~ if( NULL != result->data.dumper ) {
|
|
117
|
130
|
//~ pcap_dump((uint8_t*)result->data.dumper,
|
|
118
|
131
|
//~ (const struct pcap_pkthdr*)header,
|
|
...
|
...
|
@@ -133,7 +146,8 @@ void pcap_loop_cb(u_char *useless,const struct pcap_pkthdr* header,const u_char*
|
|
133
|
146
|
ntohs(udp_header->uh_dport));
|
|
134
|
147
|
result = inodelist_find_hashkey(hashkey);
|
|
135
|
148
|
if( NULL != result ) {
|
|
136
|
|
- printf("#%i %s reverse\n", st_packet_num, result->data.cmdline);
|
|
|
149
|
+ printf("\r\033[K#%" PRIu64 " %s reverse\n", st_packet_num, result->data.cmdline);
|
|
|
150
|
+ print_capture_progress();
|
|
137
|
151
|
if( NULL != result->data.mydumper ) {
|
|
138
|
152
|
mypcap_dump(result->data.mydumper,
|
|
139
|
153
|
(const struct pcap_pkthdr*)header,
|