Skip to content

Commit ccfa811

Browse files
committed
MOD: terminate the dump and stats thread if the sniffer was stopped
1 parent 48b314d commit ccfa811

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/server.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,31 @@ int server_run(struct server *srv, char *err) {
8181
struct pcap_stat stat;
8282

8383
if (sniffer_run(srv->sniffer) == -1) {
84+
server_terminate(srv);
8485
snprintf(err, MAX_ERR_BUFF_SIZE, "%s", pcap_geterr(srv->sniffer->pcap));
8586
return -1;
8687
}
88+
server_terminate(srv);
8789
if (srv->dumper_tid) pthread_join(srv->dumper_tid, NULL);
8890
if (srv->stats_tid) pthread_join(srv->stats_tid, NULL);
89-
pcap_stats(srv->sniffer->pcap, &stat);
90-
printf("\n======================== interface stats ========================\n");
91-
printf("%u packets received by filter\n", stat.ps_recv);
92-
printf("%u packets dropped by kernel\n", stat.ps_drop);
93-
printf("%u packets dropped by interface\n", stat.ps_ifdrop);
94-
printf("======================== interface stats ========================\n");
91+
if (!srv->opts->offline_file) {
92+
pcap_stats(srv->sniffer->pcap, &stat);
93+
printf("\n======================== interface stats ========================\n");
94+
printf("%u packets received by filter\n", stat.ps_recv);
95+
printf("%u packets dropped by kernel\n", stat.ps_drop);
96+
printf("%u packets dropped by interface\n", stat.ps_ifdrop);
97+
printf("======================== interface stats ========================\n");
98+
}
9599

96100
return 0;
97101
}
98102

99103
void server_terminate(struct server *srv) {
100-
srv->stopped = 1;
101-
sniffer_terminate(srv->sniffer);
102-
if (srv->dumper) dumper_terminate(srv->dumper);
104+
if (!srv->stopped) {
105+
srv->stopped = 1;
106+
sniffer_terminate(srv->sniffer);
107+
if (srv->dumper) dumper_terminate(srv->dumper);
108+
}
103109
}
104110

105111
void server_destroy(struct server *srv) {

0 commit comments

Comments
 (0)