extern crate nom;
extern crate pktparse;
mod tests {
use pktparse::ethernet::{EtherType, EthernetFrame, MacAddress};
use pktparse::ip::IPProtocol;
use pktparse::ipv4::IPv4Header;
use pktparse::{ethernet, ipv4};
use std::net::Ipv4Addr;
#[test]
fn ipfrag_packet() {
let bytes = [
0x00, 0x23, 0x54, 0x07, 0x93, 0x6c, 0x00, 0x1b, 0x21, 0x0f, 0x91, 0x9b, 0x08, 0x00, 0x45, 0x00, 0x05, 0xdc, 0x1a, 0xe6, 0x20, 0x00, 0x40, 0x01, 0x22, 0xed, 0x0a, 0x0a, 0x01, 0x87, 0x0a, 0x0a, 0x01, 0xb4, ];
let eth_expectation = EthernetFrame {
source_mac: MacAddress([0x00, 0x1b, 0x21, 0x0f, 0x91, 0x9b]),
dest_mac: MacAddress([0x00, 0x23, 0x54, 0x07, 0x93, 0x6c]),
ethertype: EtherType::IPv4,
};
let ip_expectation = IPv4Header {
version: 4,
ihl: 5,
tos: 0,
length: 1500,
id: 0x1ae6,
flags: 0x01,
fragment_offset: 0,
ttl: 64,
protocol: IPProtocol::ICMP,
chksum: 0x22ed,
source_addr: Ipv4Addr::new(10, 10, 1, 135),
dest_addr: Ipv4Addr::new(10, 10, 1, 180),
};
let parsed_eth_frame = ethernet::parse_ethernet_frame(&bytes);
if let Ok((remaining_data, eth_frame)) = parsed_eth_frame {
assert_eq!(eth_frame, eth_expectation);
let parsed_ip_hdr = ipv4::parse_ipv4_header(&remaining_data);
if let Ok((_remaining_data, ip_hdr)) = parsed_ip_hdr {
assert_eq!(ip_hdr, ip_expectation);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
}