..
This commit is contained in:
parent
487d129443
commit
87673afc26
1 changed files with 16 additions and 11 deletions
27
src/main.rs
27
src/main.rs
|
@ -4,9 +4,9 @@ use pnet::datalink::Channel::Ethernet;
|
|||
use pnet::datalink::{self, NetworkInterface};
|
||||
use pnet::packet::ethernet::{EtherTypes, EthernetPacket, MutableEthernetPacket};
|
||||
use pnet::packet::ip::IpNextHeaderProtocols;
|
||||
use pnet::packet::ipv4::{MutableIpv4Packet, Ipv4Packet};
|
||||
use pnet::packet::ipv6::{MutableIpv6Packet, Ipv6Packet};
|
||||
use pnet::packet::tcp::TcpPacket;
|
||||
use pnet::packet::ipv4::{self, MutableIpv4Packet, Ipv4Packet};
|
||||
use pnet::packet::ipv6::{self, MutableIpv6Packet, Ipv6Packet};
|
||||
use pnet::packet::tcp::{self, MutableTcpPacket, TcpPacket};
|
||||
use pnet::packet::{MutablePacket, Packet};
|
||||
use pnet::util::MacAddr;
|
||||
use std::env;
|
||||
|
@ -35,7 +35,6 @@ fn main() {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -83,10 +82,17 @@ fn handle_ipv4_frame<'a>(ether_frame: &EthernetPacket) -> Option<Ipv4Packet<'a>>
|
|||
IpNextHeaderProtocols::Tcp => handle_tcp_frame(&TcpPacket::new(frame.payload())?),
|
||||
_ => None,
|
||||
};
|
||||
ret.map(|x| {
|
||||
ret.map(|mut x| {
|
||||
let destination = Ipv4Addr::new(192, 168, 129, 12);
|
||||
let source = frame.get_source();
|
||||
let tcpchecksum = tcp::ipv4_checksum(&x.to_immutable(), &source, &destination);
|
||||
x.set_checksum(tcpchecksum);
|
||||
|
||||
clone.set_payload(x.packet());
|
||||
clone.set_destination(Ipv4Addr::new(192, 168, 129, 12));
|
||||
println!("{:?}", &clone);
|
||||
clone.set_destination(destination);
|
||||
|
||||
let ipchecksum = ipv4::checksum(&clone.to_immutable());
|
||||
clone.set_checksum(ipchecksum);
|
||||
clone.consume_to_immutable()
|
||||
})
|
||||
}
|
||||
|
@ -105,13 +111,12 @@ 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<MutableTcpPacket<'a>> {
|
||||
match packet.get_destination() {
|
||||
80 => {
|
||||
println!("it's HTTP! redirecting to sender!");
|
||||
let vec: Vec<u8> = packet.packet().to_owned();
|
||||
println!("{:?}", &packet);
|
||||
TcpPacket::owned(vec)
|
||||
let clone = MutableTcpPacket::owned(vec)?;
|
||||
Some(clone)
|
||||
}
|
||||
_ => {
|
||||
//println!("{:?}", &packet);
|
||||
|
|
Loading…
Reference in a new issue