cleanup
This commit is contained in:
parent
a324836a90
commit
18de53015b
|
@ -17,6 +17,12 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.12.1"
|
||||
|
@ -89,6 +95,53 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
"maybe-uninit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"lazy_static",
|
||||
"maybe-uninit",
|
||||
"memoffset",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-mac"
|
||||
version = "0.7.0"
|
||||
|
@ -108,6 +161,12 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
||||
|
||||
[[package]]
|
||||
name = "eui48"
|
||||
version = "0.4.6"
|
||||
|
@ -346,6 +405,12 @@ version = "0.1.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
||||
[[package]]
|
||||
name = "maybe-uninit"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.7.0"
|
||||
|
@ -358,6 +423,15 @@ version = "2.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.6.22"
|
||||
|
@ -653,6 +727,30 @@ dependencies = [
|
|||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"crossbeam-queue",
|
||||
"crossbeam-utils",
|
||||
"lazy_static",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.56"
|
||||
|
@ -682,6 +780,20 @@ name = "serde"
|
|||
version = "1.0.110"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.110"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
|
@ -853,6 +965,7 @@ dependencies = [
|
|||
"eui48",
|
||||
"libc",
|
||||
"pcap",
|
||||
"rayon",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
|
|
|
@ -17,5 +17,5 @@ eui48 = "~0.4.6"
|
|||
#time = {version = "~0.2", default-features = false }
|
||||
#serde_json = "1.0"
|
||||
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||
serde = "1.0.3"
|
||||
serde = { version = "1.0.3", features = ["derive"] }
|
||||
rayon = "1.3"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"insert_max": 20000,
|
||||
"filter": "tcp && !ip6",
|
||||
"filter": "tcp && ip6",
|
||||
"from_device": false,
|
||||
"parse_device": "enp7s0",
|
||||
"pcap_file": "../target/wohnung2.pcapng",
|
||||
|
|
|
@ -4,9 +4,16 @@ extern crate eui48;
|
|||
mod packet_handler;
|
||||
use pcap::Capture;
|
||||
use eui48::MacAddress;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
//use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::str;
|
||||
|
||||
|
||||
/* protocol ids, LittleEndian */
|
||||
const ETH_P_IPV6: usize = 0xDD86;
|
||||
const ETH_P_IP: usize = 0x08;
|
||||
const TCP: usize = 0x06;
|
||||
|
||||
|
||||
fn build_ether () -> packet_handler::EtherHeader {
|
||||
packet_handler::EtherHeader {
|
||||
ether_dhost: (MacAddress::new([0;6])).to_hex_string(),
|
||||
|
@ -43,31 +50,26 @@ pub fn parse (parse_file: &str, filter_str: &str) -> Vec<QryData> {
|
|||
};
|
||||
let mut v: Vec<QryData> = Vec::new();
|
||||
|
||||
//let mut cap = Capture::from_file("../target/wohnung2.pcapng").unwrap();
|
||||
let mut cap = Capture::from_file(parse_file).unwrap();
|
||||
//let filter_str: String = "tcp && !ip6".to_owned();
|
||||
//let filter_str: String = "tcp && ip dst 18.202.15.201".to_owned();
|
||||
//let filter_str: String = "tcp && ip dst 192.168.0.7".to_owned();
|
||||
//println!("{:?}", filter_str);
|
||||
Capture::filter(&mut cap, &filter_str).unwrap();
|
||||
|
||||
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());
|
||||
me.ether_header = packet_handler::ethernet_handler( packet.data );
|
||||
if 8 == me.ether_header.ether_type {
|
||||
if ETH_P_IP == me.ether_header.ether_type as usize {
|
||||
me.ipv6_header = None::<packet_handler::IpV6Header>;
|
||||
me.ipv4_header = Some(packet_handler::ip_handler( packet.data )).unwrap();
|
||||
if 6 == me.ipv4_header.unwrap().ip_protocol {
|
||||
if TCP == me.ipv4_header.unwrap().ip_protocol as usize {
|
||||
me.tcp_header = Some(packet_handler::tcp_handler( me.ipv4_header.unwrap().ip_ihl, packet.data )).unwrap();
|
||||
me.data= packet_handler::payload_handler( me.ipv4_header.unwrap().ip_ihl, me.tcp_header.unwrap().data_offset, packet.data);
|
||||
}
|
||||
|
||||
}
|
||||
if 56710 == me.ether_header.ether_type{
|
||||
if ETH_P_IPV6 == me.ether_header.ether_type as usize {
|
||||
me.ipv4_header = None::<packet_handler::IpV4Header>;
|
||||
me.ipv6_header = Some(packet_handler::ipv6_handler( packet.data )).unwrap();
|
||||
if 6 == me.ipv6_header.unwrap().next_header{
|
||||
if TCP == me.ipv6_header.unwrap().next_header as usize{
|
||||
me.tcp_header = Some(packet_handler::tcp_handler( 10, packet.data )).unwrap();
|
||||
me.data = packet_handler::payload_handler( 10, 0, packet.data);
|
||||
}
|
||||
|
@ -81,9 +83,6 @@ pub fn parse (parse_file: &str, filter_str: &str) -> Vec<QryData> {
|
|||
|
||||
pub fn parse_device (parse_device: &str, filter_str: &str, insert_max: &usize) -> Vec<QryData> {
|
||||
let ether_init = build_ether();
|
||||
let ipv4_init = build_ipv4();
|
||||
let ipv6_init = build_ipv6();
|
||||
//let tcp_init = build_tcp();
|
||||
|
||||
let mut me = QryData {
|
||||
id: 0,
|
||||
|
@ -102,19 +101,19 @@ pub fn parse_device (parse_device: &str, filter_str: &str, insert_max: &usize) -
|
|||
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());
|
||||
me.ether_header = packet_handler::ethernet_handler( packet.data );
|
||||
if 8 == me.ether_header.ether_type {
|
||||
if ETH_P_IP == me.ether_header.ether_type as usize {
|
||||
me.ipv6_header = None::<packet_handler::IpV6Header>;
|
||||
me.ipv4_header = Some(packet_handler::ip_handler( packet.data )).unwrap();
|
||||
if 6 == me.ipv4_header.unwrap().ip_protocol {
|
||||
if TCP == me.ipv4_header.unwrap().ip_protocol as usize{
|
||||
me.tcp_header = Some(packet_handler::tcp_handler( me.ipv4_header.unwrap().ip_ihl, packet.data )).unwrap();
|
||||
me.data= packet_handler::payload_handler( me.ipv4_header.unwrap().ip_ihl, me.tcp_header.unwrap().data_offset, packet.data);
|
||||
}
|
||||
|
||||
}
|
||||
if 56710 == me.ether_header.ether_type{
|
||||
if ETH_P_IPV6 == me.ether_header.ether_type as usize {
|
||||
me.ipv4_header = None::<packet_handler::IpV4Header>;
|
||||
me.ipv6_header = Some(packet_handler::ipv6_handler( packet.data)).unwrap();
|
||||
if 6 == me.ipv6_header.unwrap().next_header{
|
||||
if TCP == me.ipv6_header.unwrap().next_header as usize {
|
||||
me.tcp_header = Some(packet_handler::tcp_handler( 10, packet.data )).unwrap();
|
||||
me.data = packet_handler::payload_handler( 10, 0, packet.data);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue