Skip to content
Browse files

Fix crash opening offline file.

Newer versions of libpcap don't let you set nonblocking mode on
files (and apparently don't set a useful error message).
  • Loading branch information...
1 parent 5831e36 commit 584ee107f17440fef1c8d10a4e821877a78a0540 Muir Manders committed Jan 27, 2014
Showing with 8 additions and 5 deletions.
  1. +5 −1 pcap_binding.cc
  2. +3 −4 pcap_session.cc
View
6 pcap_binding.cc
@@ -101,10 +101,14 @@ DefaultDevice(const Arguments& args)
pcap_addr_t *addr;
bool found = false;
- if (pcap_findalldevs(&alldevs, errbuf) == -1 || alldevs == NULL) {
+ if (pcap_findalldevs(&alldevs, errbuf) == -1) {
return ThrowException(Exception::Error(String::New(errbuf)));
}
+ if (alldevs == NULL) {
+ return ThrowException(Exception::Error(String::New("pcap_findalldevs didn't find any devs")));
+ }
+
for (dev = alldevs; dev != NULL; dev = dev->next) {
if (dev->addresses != NULL && !(dev->flags & PCAP_IF_LOOPBACK)) {
for (addr = dev->addresses; addr != NULL; addr = addr->next) {
View
7 pcap_session.cc
@@ -218,6 +218,9 @@ PcapSession::Open(bool live, const Arguments& args)
}
}
+ if (pcap_setnonblock(session->pcap_handle, 1, errbuf) == -1) {
+ return ThrowException(Exception::Error(String::New(errbuf)));
+ }
} else {
// Device is the path to the savefile
session->pcap_handle = pcap_open_offline((char *) *device, errbuf);
@@ -226,10 +229,6 @@ PcapSession::Open(bool live, const Arguments& args)
}
}
- if (pcap_setnonblock(session->pcap_handle, 1, errbuf) == -1) {
- return ThrowException(Exception::Error(String::New(errbuf)));
- }
-
if (filter.length() != 0) {
if (pcap_compile(session->pcap_handle, &session->fp, (char *) *filter, 1, session->net) == -1) {
return ThrowException(Exception::Error(String::New(pcap_geterr(session->pcap_handle))));

0 comments on commit 584ee10

Please sign in to comment.
Something went wrong with that request. Please try again.