From 487d129443c70f95446a624c327b43da02d4bafe Mon Sep 17 00:00:00 2001 From: hexchen Date: Sat, 2 May 2020 22:22:06 +0000 Subject: [PATCH] . --- src/main.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 533337c..f4db062 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use pnet::packet::tcp::TcpPacket; use pnet::packet::{MutablePacket, Packet}; use pnet::util::MacAddr; use std::env; +use std::net::Ipv4Addr; fn main() { let interface_name = env::args().nth(1).unwrap(); @@ -31,8 +32,12 @@ fn main() { loop { match rx.next() { Ok(packet) => { - if handle_ethernet_frame(packet, own_mac).is_none() { - println!("something broke. cool."); + match handle_ethernet_frame(packet, own_mac) { + None => (),//println!("something broke. cool."), + Some(x) => { + println!("Sending out packet {:?}", &x); + tx.send_to(x.packet(), None); + } } } Err(e) => { @@ -64,8 +69,8 @@ fn handle_ethernet_frame(packet: &[u8], own_mac: MacAddr) -> Option None, }; ret.map(|mut x| { - x.set_destination(frame.get_source()); - x.set_source(frame.get_destination()); + x.set_destination(MacAddr::new(0xdc, 0xa6, 0x32, 0x49, 0x87, 0xcd)); + //x.set_source(own_mac); x.consume_to_immutable() }) } @@ -80,6 +85,8 @@ fn handle_ipv4_frame<'a>(ether_frame: &EthernetPacket) -> Option> }; ret.map(|x| { clone.set_payload(x.packet()); + clone.set_destination(Ipv4Addr::new(192, 168, 129, 12)); + println!("{:?}", &clone); clone.consume_to_immutable() }) } @@ -99,12 +106,16 @@ fn handle_ipv6_frame<'a>(ether_frame: &EthernetPacket) -> Option> } fn handle_tcp_frame<'a>(packet: &TcpPacket) -> Option> { - println!("{:?}", packet); match packet.get_destination() { 80 => { + println!("it's HTTP! redirecting to sender!"); let vec: Vec = packet.packet().to_owned(); + println!("{:?}", &packet); TcpPacket::owned(vec) } - _ => None, + _ => { + //println!("{:?}", &packet); + None + }, } }