-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdumpfile_devicetracker.cc
More file actions
125 lines (91 loc) · 3.4 KB
/
dumpfile_devicetracker.cc
File metadata and controls
125 lines (91 loc) · 3.4 KB
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
/*
This file is part of Kismet
Kismet 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 2 of the License, or
(at your option) any later version.
Kismet 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 Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <errno.h>
#include "globalregistry.h"
#include "dumpfile_devicetracker.h"
#include "devicetracker.h"
Dumpfile_Devicetracker::Dumpfile_Devicetracker() {
fprintf(stderr, "FATAL OOPS: Dumpfile_Devicetracker()\n");
exit(1);
}
// Complex constructor for devicetracker to register its own global formats
Dumpfile_Devicetracker::Dumpfile_Devicetracker(GlobalRegistry *in_globalreg,
string in_type, string in_class) : Dumpfile(in_globalreg) {
type = in_type;
logclass = in_class;
logfile = NULL;
Devicetracker *tracker = (Devicetracker *) globalreg->FetchGlobal("DEVICE_TRACKER");
if (tracker == NULL) {
_MSG("Kismet phy-neutral devicetracker not present; did you disable it "
"in the config file? Devicetracker depends on the new phy-neutral code.",
MSGFLAG_ERROR | MSGFLAG_PRINTERROR);
return;
}
globalreg->InsertGlobal("DUMPFILE_" + in_type, this);
if ((fname = ProcessConfigOpt()) == "" || globalreg->fatal_condition) {
return;
}
if ((logfile = fopen(fname.c_str(), "w")) == NULL) {
_MSG("Failed to open devicetracker " + type + " log file '" +
fname + "': " + strerror(errno),
MSGFLAG_FATAL);
globalreg->fatal_condition = 1;
return;
}
globalreg->RegisterDumpFile(this);
_MSG("Opened Devicetracker " + logclass + " log file '" + fname + "'",
MSGFLAG_INFO);
}
Dumpfile_Devicetracker::Dumpfile_Devicetracker(GlobalRegistry *in_globalreg) {
fprintf(stderr, "FATAL OOPS: Dumpfile_Devicetracker(globalreg)\n");
exit(1);
}
Dumpfile_Devicetracker::~Dumpfile_Devicetracker() {
if (logfile != NULL)
Flush();
logfile = NULL;
if (export_filter != NULL)
delete export_filter;
}
int Dumpfile_Devicetracker::Flush() {
Devicetracker *tracker = (Devicetracker *) globalreg->FetchGlobal("DEVICE_TRACKER");
if (tracker == NULL) {
_MSG("Kismet phy-neutral devicetracker not present; did you disable it "
"in the config file? Devicetracker depends on the new phy-neutral code.",
MSGFLAG_ERROR | MSGFLAG_PRINTERROR);
return -1;
}
if (logfile != NULL)
fclose(logfile);
string tempname = fname + ".temp";
if ((logfile = fopen(tempname.c_str(), "w")) == NULL) {
_MSG("Failed to open temporary device " + logclass + " file for writing: " +
string(strerror(errno)), MSGFLAG_ERROR);
return -1;
}
// Kick the device_tracker logger
int ret = tracker->LogDevices(logclass, type, logfile);
fflush(logfile);
fclose(logfile);
logfile = NULL;
if (rename(tempname.c_str(), fname.c_str()) < 0) {
_MSG("Failed to rename device " + logclass + " file " + tempname + " to " +
fname + ": " + string(strerror(errno)), MSGFLAG_ERROR);
return -1;
}
dumped_frames = tracker->FetchNumDevices(KIS_PHY_ANY);
return ret;
}