Skip to content

Commit

Permalink
refactor: refactor key parse flow
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Mar 21, 2024
1 parent 6ec83d1 commit 3cd63a1
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/net/parser/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use pnet::packet::ethernet::EthernetPacket;
use pnet::packet::ipv4::Ipv4Packet;
use pnet::packet::ipv6::Ipv6Packet;
use pnet::packet::udp::UdpPacket;

use pnet::packet::Packet;

use log::trace;

use crate::net::parser::{parse_ports, protocol_to_number};
use crate::net::types::{Key, MacAddress};
use crate::net::NetError;
Expand Down Expand Up @@ -108,43 +111,30 @@ pub fn parse_keys(packet: pcap::Packet) -> Result<(Key, Key), NetError> {
return Err(NetError::EmptyPacket);
}

let ipv6 = ipv6_keys(i);
match ipv6 {
Ok(_) => {}
Err(e) => return Err(e),
}
trace!("IPv6 packet detected");

ipv6.unwrap()
ipv6_keys(i)?
}
EtherTypes::Ipv4 => {
let i = Ipv4Packet::new(ethernet_packet.payload()).unwrap();
if i.payload().is_empty() {
return Err(NetError::EmptyPacket);
}

let ipv4 = ipv4_keys(i);
match ipv4 {
Ok(_) => {}
Err(e) => return Err(e),
}
trace!("IPv4 packet detected");

ipv4.unwrap()
ipv4_keys(i)?
}
EtherTypes::Arp => {
let i = ArpPacket::new(ethernet_packet.payload()).unwrap();
//if i.payload().is_empty() {
// return Err(NetError::EmptyPacket);
//}
//println!("AHHHHHH");
let arp = arp_keys(i);
match arp {
Ok(_) => {}
Err(e) => return Err(e),
}

arp.unwrap()
}
trace!("ARP packet detected");

arp_keys(i)?
}
_ => {
return Err(NetError::UnknownEtherType(
ethernet_packet.get_ethertype().to_string(),
Expand Down

0 comments on commit 3cd63a1

Please sign in to comment.