.
This commit is contained in:
parent
2ce8203628
commit
487d129443
1 changed files with 17 additions and 6 deletions
23
src/main.rs
23
src/main.rs
|
@ -10,6 +10,7 @@ use pnet::packet::tcp::TcpPacket;
|
||||||
use pnet::packet::{MutablePacket, Packet};
|
use pnet::packet::{MutablePacket, Packet};
|
||||||
use pnet::util::MacAddr;
|
use pnet::util::MacAddr;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let interface_name = env::args().nth(1).unwrap();
|
let interface_name = env::args().nth(1).unwrap();
|
||||||
|
@ -31,8 +32,12 @@ fn main() {
|
||||||
loop {
|
loop {
|
||||||
match rx.next() {
|
match rx.next() {
|
||||||
Ok(packet) => {
|
Ok(packet) => {
|
||||||
if handle_ethernet_frame(packet, own_mac).is_none() {
|
match handle_ethernet_frame(packet, own_mac) {
|
||||||
println!("something broke. cool.");
|
None => (),//println!("something broke. cool."),
|
||||||
|
Some(x) => {
|
||||||
|
println!("Sending out packet {:?}", &x);
|
||||||
|
tx.send_to(x.packet(), None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -64,8 +69,8 @@ fn handle_ethernet_frame(packet: &[u8], own_mac: MacAddr) -> Option<EthernetPack
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
ret.map(|mut x| {
|
ret.map(|mut x| {
|
||||||
x.set_destination(frame.get_source());
|
x.set_destination(MacAddr::new(0xdc, 0xa6, 0x32, 0x49, 0x87, 0xcd));
|
||||||
x.set_source(frame.get_destination());
|
//x.set_source(own_mac);
|
||||||
x.consume_to_immutable()
|
x.consume_to_immutable()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -80,6 +85,8 @@ fn handle_ipv4_frame<'a>(ether_frame: &EthernetPacket) -> Option<Ipv4Packet<'a>>
|
||||||
};
|
};
|
||||||
ret.map(|x| {
|
ret.map(|x| {
|
||||||
clone.set_payload(x.packet());
|
clone.set_payload(x.packet());
|
||||||
|
clone.set_destination(Ipv4Addr::new(192, 168, 129, 12));
|
||||||
|
println!("{:?}", &clone);
|
||||||
clone.consume_to_immutable()
|
clone.consume_to_immutable()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -99,12 +106,16 @@ fn handle_ipv6_frame<'a>(ether_frame: &EthernetPacket) -> Option<Ipv6Packet<'a>>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_tcp_frame<'a>(packet: &TcpPacket) -> Option<TcpPacket<'a>> {
|
fn handle_tcp_frame<'a>(packet: &TcpPacket) -> Option<TcpPacket<'a>> {
|
||||||
println!("{:?}", packet);
|
|
||||||
match packet.get_destination() {
|
match packet.get_destination() {
|
||||||
80 => {
|
80 => {
|
||||||
|
println!("it's HTTP! redirecting to sender!");
|
||||||
let vec: Vec<u8> = packet.packet().to_owned();
|
let vec: Vec<u8> = packet.packet().to_owned();
|
||||||
|
println!("{:?}", &packet);
|
||||||
TcpPacket::owned(vec)
|
TcpPacket::owned(vec)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => {
|
||||||
|
//println!("{:?}", &packet);
|
||||||
|
None
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue