changed first if loop to match statement

This commit is contained in:
gurkenhabicht 2020-05-21 01:48:13 +02:00
parent 59e96a1205
commit 45d69dd97f
1 changed files with 65 additions and 61 deletions

View File

@ -5,9 +5,9 @@ mod packet_handler;
use eui48::MacAddress;
use pcap::Capture;
//use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::str;
use regex::bytes::Regex;
use regex::bytes::Match;
use regex::bytes::Regex;
use std::str;
/* protocol ids, LittleEndian */
const ETH_P_IPV6: usize = 0xDD86;
@ -34,17 +34,14 @@ pub struct QryData {
pub tcp_header: Option<packet_handler::TcpHeader>,
}
fn flag_carnage( re: &Regex, payload: &[u8]) -> Option<String> {
//let _payload: [u8] = payload.copy_from_slice(&payload);
for mat in re.find_iter(payload){
//println!("{:?}", mat.as_bytes().to_owned().as_string());
fn flag_carnage(re: &Regex, payload: &[u8]) -> Option<String> {
for mat in re.find_iter(payload) {
println!("{:?}", std::str::from_utf8(mat.as_bytes()));
}
Some("test".to_owned())
}
pub fn parse(parse_file: &str, filter_str: &str) -> Vec<QryData> {
let ether_init = build_ether();
@ -65,9 +62,10 @@ pub fn parse(parse_file: &str, filter_str: &str) -> Vec<QryData> {
while let Ok(packet) = cap.next() {
me.time = (packet.header.ts.tv_usec as f64 / 1000000.0) + packet.header.ts.tv_sec as f64;
me.data = Some(packet.data.to_vec());
flag_carnage( &re, packet.data);
flag_carnage(&re, packet.data);
me.ether_header = packet_handler::ethernet_handler(packet.data);
if ETH_P_IP == me.ether_header.ether_type as usize {
match me.ether_header.ether_type as usize {
ETH_P_IP => {
me.ipv6_header = None::<packet_handler::IpV6Header>;
me.ipv4_header = Some(packet_handler::ip_handler(packet.data)).unwrap();
if TCP == me.ipv4_header.unwrap().ip_protocol as usize {
@ -83,7 +81,7 @@ pub fn parse(parse_file: &str, filter_str: &str) -> Vec<QryData> {
);
}
}
if ETH_P_IPV6 == me.ether_header.ether_type as usize {
ETH_P_IPV6 => {
me.ipv4_header = None::<packet_handler::IpV4Header>;
me.ipv6_header = Some(packet_handler::ipv6_handler(packet.data)).unwrap();
if TCP == me.ipv6_header.unwrap().next_header as usize {
@ -96,6 +94,8 @@ pub fn parse(parse_file: &str, filter_str: &str) -> Vec<QryData> {
}
}
_ => println!("network protocol not implemented"),
}
v.push(QryData {
id: 0,
time: me.time,
@ -129,8 +129,10 @@ pub fn parse_device(parse_device: &str, filter_str: &str, insert_max: &usize) ->
'parse: while let Ok(packet) = cap.next() {
me.time = (packet.header.ts.tv_usec as f64 / 1000000.0) + packet.header.ts.tv_sec as f64;
me.data = Some(packet.data.to_vec());
flag_carnage(&re, packet.data);
me.ether_header = packet_handler::ethernet_handler(packet.data);
if ETH_P_IP == me.ether_header.ether_type as usize {
match me.ether_header.ether_type as usize {
ETH_P_IP => {
me.ipv6_header = None::<packet_handler::IpV6Header>;
me.ipv4_header = Some(packet_handler::ip_handler(packet.data)).unwrap();
if TCP == me.ipv4_header.unwrap().ip_protocol as usize {
@ -146,7 +148,7 @@ pub fn parse_device(parse_device: &str, filter_str: &str, insert_max: &usize) ->
);
}
}
if ETH_P_IPV6 == me.ether_header.ether_type as usize {
ETH_P_IPV6 => {
me.ipv4_header = None::<packet_handler::IpV4Header>;
me.ipv6_header = Some(packet_handler::ipv6_handler(packet.data)).unwrap();
if TCP == me.ipv6_header.unwrap().next_header as usize {
@ -159,6 +161,8 @@ pub fn parse_device(parse_device: &str, filter_str: &str, insert_max: &usize) ->
}
}
_ => println!("network protocol not implemented"),
}
v.push(QryData {
id: 0,
time: me.time,