Skip to content

Commit

Permalink
Fix crash opening offline file.
Browse files Browse the repository at this point in the history
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
Muir Manders committed Jan 27, 2014
1 parent 5831e36 commit 584ee10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pcap_binding.cc
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions pcap_session.cc
Expand Up @@ -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);
Expand All @@ -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))));
Expand Down

0 comments on commit 584ee10

Please sign in to comment.