Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit35b62b4

Browse files
committed
Allow user to handle pcap warnings
1 parent798857a commit35b62b4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

‎pcap.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ exports.TCPTracker = tcp_tracker.TCPTracker;
1111
exports.TCPSession=tcp_tracker.TCPSession;
1212
exports.DNSCache=DNSCache;
1313

14+
// This may be overriden by the user
15+
exports.warningHandler=functionwarningHandler(x){
16+
console.warn('warning: %s - this may not actually work',x);
17+
};
18+
1419
functionPcapSession(is_live,device_name,filter,buffer_size,snap_length,outfile,is_monitor,buffer_timeout){
1520
this.is_live=is_live;
1621
this.device_name=device_name;
@@ -51,9 +56,9 @@ function PcapSession(is_live, device_name, filter, buffer_size, snap_length, out
5156
constpacket_ready=this.on_packet_ready.bind(this);
5257
if(this.is_live){
5358
this.device_name=this.device_name||binding.default_device();
54-
this.link_type=this.session.open_live(this.device_name,this.filter,this.buffer_size,this.snap_length,this.outfile,packet_ready,this.is_monitor,this.buffer_timeout);
59+
this.link_type=this.session.open_live(this.device_name,this.filter,this.buffer_size,this.snap_length,this.outfile,packet_ready,this.is_monitor,this.buffer_timeout,exports.warningHandler);
5560
}else{
56-
this.link_type=this.session.open_offline(this.device_name,this.filter,this.buffer_size,this.snap_length,this.outfile,packet_ready,this.is_monitor,this.buffer_timeout);
61+
this.link_type=this.session.open_offline(this.device_name,this.filter,this.buffer_size,this.snap_length,this.outfile,packet_ready,this.is_monitor,this.buffer_timeout,exports.warningHandler);
5762
}
5863

5964
this.opened=true;

‎pcap_session.cc‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void PcapSession::Open(bool live, const Nan::FunctionCallbackInfo<Value>& info)
135135
Nan::HandleScope scope;
136136
char errbuf[PCAP_ERRBUF_SIZE];
137137

138-
if (info.Length() ==8) {
138+
if (info.Length() ==9) {
139139
if (!info[0]->IsString()) {
140140
Nan::ThrowTypeError("pcap Open: info[0] must be a String");
141141
return;
@@ -168,6 +168,10 @@ void PcapSession::Open(bool live, const Nan::FunctionCallbackInfo<Value>& info)
168168
Nan::ThrowTypeError("pcap Open: info[7] must be a Number");
169169
return;
170170
}
171+
if (!info[8]->IsFunction()) {// warning function
172+
Nan::ThrowTypeError("pcap Open: info[8] must be a Function");
173+
return;
174+
}
171175
}else {
172176
Nan::ThrowTypeError("pcap Open: expecting 8 arguments");
173177
return;
@@ -188,7 +192,8 @@ void PcapSession::Open(bool live, const Nan::FunctionCallbackInfo<Value>& info)
188192
if (pcap_lookupnet((char *) *device, &session->net, &session->mask, errbuf) == -1) {
189193
session->net =0;
190194
session->mask =0;
191-
fprintf(stderr,"warning: %s - this may not actually work\n", errbuf);
195+
Local<Value> str =Nan::New(errbuf).ToLocalChecked();
196+
Nan::Call(info[8].As<Function>(),Nan::GetCurrentContext()->Global(),1, &str);
192197
}
193198

194199
session->pcap_handle =pcap_create((char *) *device, errbuf);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp