-
Notifications
You must be signed in to change notification settings - Fork 1
/
signal.c
89 lines (65 loc) · 2.39 KB
/
signal.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
/*
Exciting Licence Info.....
This file is part of FingerprinTLS.
FingerprinTLS 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.
FingerprinTLS 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
Exciting Licence Info Addendum.....
FingerprinTLS is additionally released under the "don't judge me" program
whereby it is forbidden to rip into me too harshly for programming
mistakes, kthnxbai.
*/
/* This File Is To Cope With Signal Handling Routines */
void sig_handler (int signo);
/* Function registers all the signals to the sig_handler function */
int register_signals() {
if (signal(SIGUSR1, sig_handler) == SIG_ERR)
return 0;
if (signal(SIGUSR2, sig_handler) == SIG_ERR)
return 0;
if (signal(SIGINT, sig_handler) == SIG_ERR)
return 0;
return 1;
}
/* Handles a variety of signals being recieved */
void sig_handler (int signo) {
struct pcap_stat pstats;
extern FILE *log_fd;
extern pcap_t *handle; /* packet capture handle */
extern pcap_dumper_t *output_handle;
extern struct bpf_program fp; /* compiled filter program (expression) */
switch (signo) {
/* Placeholder, will use this for some debugging */
case SIGUSR1:
// This is where code goes :)
break;
/* Someone has ctrl-c'd the process.... deal */
case SIGINT:
// Close File Pointers
// Not even going to check, because, APP GOING DOWN!!
fclose(log_fd);
// Sort out libpcap stuff
// Get some stats on the session
if(!(pcap_stats(handle, &pstats))) {
printf("Processed %i%% Of Packets\n",
(int) (( (float)((float)pstats.ps_recv - (float)pstats.ps_drop) / (float) pstats.ps_recv) * 100) );
printf("Recieved: %i\n", pstats.ps_recv);
printf("Dropped: %i\n", pstats.ps_drop);
}
// No checking because accoring to the man page, they don't return anything useful o_O
pcap_freecode(&fp);
pcap_close(handle);
if(output_handle != NULL) {
pcap_dump_close(output_handle);
}
exit(1);
break;
}
}