pub use std::array;
pub use std::collections::{BTreeSet, HashMap};
-pub use std::convert::TryInto;
+pub use std::convert::{TryFrom, TryInto};
pub use std::borrow::Cow;
pub use std::cmp::{min, max};
pub use std::fs;
pub use std::io::{self, ErrorKind, Read as _};
pub use std::iter;
pub use std::mem;
-pub use std::net::{IpAddr, Ipv4Addr};
+pub use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
pub use std::path::{Path, PathBuf};
pub use std::panic;
pub use std::process;
fn from(frames: Frames) -> FramesData { frames.frames }
}
+pub fn ip_packet_addrs(packet: &[u8]) -> Option<(IpAddr, IpAddr)> {
+ Some(match packet.get(0)? & 0xf0 {
+ 4 if packet.len() >= 20 => (
+ Ipv4Addr::from(*<&[u8;4]>::try_from(&packet[12..16]).unwrap()).into(),
+ Ipv4Addr::from(*<&[u8;4]>::try_from(&packet[16..20]).unwrap()).into(),
+ ),
+
+ 6 if packet.len() >= 40 => (
+ Ipv6Addr::from(*<&[u8;16]>::try_from(&packet[ 8..24]).unwrap()).into(),
+ Ipv6Addr::from(*<&[u8;16]>::try_from(&packet[24..40]).unwrap()).into(),
+ ),
+
+ _ => None?,
+ })
+}
+
#[derive(Copy,Clone,Eq,PartialEq,Ord,PartialOrd,Hash)]
pub struct DumpHex<'b>(pub &'b [u8]);
impl Debug for DumpHex<'_> {