node-pcap / node_pcap

libpcap bindings for node
MIT License
928 stars 253 forks source link

speed server example is not working, and crashing #272

Open sanehab opened 3 years ago

sanehab commented 3 years ago

Hey,

While trying to browse through the examples i have found that the speed_server example is not working, due to the following code, findalldevs is undefined and not a function:

const pcap_session = pcap.createSession(process.argv[2], {
  filter: process.argv[3],
})

// Print all devices, currently listening device prefixed with an asterisk
console.log("All devices:")
console.log(pcap_session)
pcap_session.findalldevs().forEach(function (dev) {
    if (pcap_session.device_name === dev.name) {
        console.log("* ");
    }
    console.log(dev.name + " ");
    if (dev.addresses.length > 0) {
        dev.addresses.forEach(function (address) {
            console.log(address.addr + "/" + address.netmask);
        });
        console.log("\n");
    } else {
        console.log("no address\n");
    }
});

also note that the following code is not doing anything since the tcp_tracker does not emit any event called http request, this event was emitted however in previous versions

tcp_tracker.on("http request", function (session, http) {
  var matches = /send_file\?id=(\d+)/.exec(http.request.url)
  if (matches && matches[1]) {
    session.track_id = matches[1]
    console.log("Added tracking for " + matches[1])
  } else {
    console.log("Didn't add tracking for " + http.request.url)
  }
})

Thanks

TankNee commented 3 years ago

Hey, when I looked through the pcap.js file, I found that the findalldevs function was defined to an isolate function and it had been exported independently! So, I reckoned that you'd replace the pcap_session.findalldevs with pcap.findalldevs! It works on my device: Windows WSL Ubuntu 20.