Included debug messages, fixed problem with some network interfaces
This commit is contained in:
Generated
+1
@@ -404,6 +404,7 @@ dependencies = [
|
|||||||
name = "packet_sniffer"
|
name = "packet_sniffer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pnet 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pnet 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pnet = "0.22.0"
|
pnet = "0.22.0"
|
||||||
|
log = { version = "0.4", features = ["std"] }
|
||||||
@@ -15,6 +15,8 @@ use pnet::packet::udp;
|
|||||||
use pnet::packet::Packet;
|
use pnet::packet::Packet;
|
||||||
use pnet::util::MacAddr;
|
use pnet::util::MacAddr;
|
||||||
|
|
||||||
|
use log::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct UdpPacket {
|
pub struct UdpPacket {
|
||||||
pub interface_name: String,
|
pub interface_name: String,
|
||||||
@@ -35,6 +37,8 @@ pub fn receive(tx: Sender<UdpPacket>) {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|i| !i.is_loopback());
|
.filter(|i| !i.is_loopback());
|
||||||
|
|
||||||
|
debug!("Found interfaces: {:?}", interfaces);
|
||||||
|
|
||||||
for interface in interfaces {
|
for interface in interfaces {
|
||||||
let tx = shared_tx.clone();
|
let tx = shared_tx.clone();
|
||||||
let config = pnet::datalink::Config{
|
let config = pnet::datalink::Config{
|
||||||
@@ -46,8 +50,14 @@ pub fn receive(tx: Sender<UdpPacket>) {
|
|||||||
// Create a channel to receive on
|
// Create a channel to receive on
|
||||||
let (_, mut rx) = match datalink::channel(&interface, config) {
|
let (_, mut rx) = match datalink::channel(&interface, config) {
|
||||||
Ok(Ethernet(tx, rx)) => (tx, rx),
|
Ok(Ethernet(tx, rx)) => (tx, rx),
|
||||||
Ok(_) => panic!("packetdump: unhandled channel type: {}"),
|
Ok(_) => {
|
||||||
Err(e) => panic!("packetdump: unable to create channel: {}", e),
|
warn!("packetdump: unhandled channel type");
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
warn!("packetdump: unable to create channel: {}", e);
|
||||||
|
continue;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ fn initialize(_py: Python) -> PyResult<u32> {
|
|||||||
let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel();
|
let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel();
|
||||||
|
|
||||||
packet_sniffer::receive(tx);
|
packet_sniffer::receive(tx);
|
||||||
|
info!("Listening to network packets...");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(packet) = rx.recv() {
|
if let Ok(packet) = rx.recv() {
|
||||||
|
|||||||
Reference in New Issue
Block a user