fix ipv6 src&dst ip representation in PacketInfo
This commit is contained in:
parent
eedb2c5d02
commit
f74089a365
1 changed files with 8 additions and 7 deletions
|
|
@ -47,12 +47,12 @@ impl fmt::Display for PacketInfo {
|
|||
if self.version() == &IpVersion::V4 {
|
||||
let src_ip = self.src_ipv4_ip().unwrap();
|
||||
let dst_ip = self.dst_ipv4_ip().unwrap();
|
||||
write!(f, "{:?} {}.{}.{}.{}:{} -> {}.{}.{}.{}:{} {:?} is dns? {:?}", self.version(), src_ip[0], src_ip[1], src_ip[2], src_ip[3], self.src_port(), dst_ip[0], dst_ip[1], dst_ip[2], dst_ip[3], self.dst_port(), self.protocol(), self.dns())
|
||||
write!(f, "{}.{}.{}.{}:{} -> {}.{}.{}.{}:{} {:?} is dns? {:?}", src_ip[0], src_ip[1], src_ip[2], src_ip[3], self.src_port(), dst_ip[0], dst_ip[1], dst_ip[2], dst_ip[3], self.dst_port(), self.protocol(), self.dns())
|
||||
} else {
|
||||
let src_ip = self.src_ipv6_ip().unwrap();
|
||||
let dst_ip = self.dst_ipv6_ip().unwrap();
|
||||
// y:y:y:y:y:y:y:y = 8 hexademical
|
||||
write!(f, "{:?} {}:{}:{}:{}:{}:{}:{}:{} port:{} -> {}:{}:{}:{}:{}:{}:{}:{} port:{} {:?} is dns? {:?}", self.version(), src_ip[0], src_ip[1], src_ip[2], src_ip[3], src_ip[4], src_ip[5], src_ip[6], src_ip[7], self.src_port(), dst_ip[0], dst_ip[1], dst_ip[2], dst_ip[3], dst_ip[4], dst_ip[5], dst_ip[6], dst_ip[7], self.dst_port(), self.protocol(), self.dns())
|
||||
// y:y:y:y:y:y:y:y = 8 hexademical; y = segment, pair of 2 u8 big endian
|
||||
write!(f, "{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x} port:{} -> {:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x} port:{} {:?} is dns? {:?}", src_ip[0], src_ip[1], src_ip[2], src_ip[3], src_ip[4], src_ip[5], src_ip[6], src_ip[7], self.src_port(), dst_ip[0], dst_ip[1], dst_ip[2], dst_ip[3], dst_ip[4], dst_ip[5], dst_ip[6], dst_ip[7], self.dst_port(), self.protocol(), self.dns())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -150,16 +150,17 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
|
|||
Ok(v4)
|
||||
},
|
||||
6 => {
|
||||
// FIXME: fix ipv6 type representation to u16 paired u8
|
||||
let src_ip_bytes = &packet[8..24];
|
||||
let src_ip = src_ip_bytes.chunks(2).map(|b| u16::from_be_bytes(b[0], b[1]));
|
||||
// y:y:y:y:y:y:y:y hexademical; y = segment, pair of 2 u8 in big endian
|
||||
let src_ip = std::array::from_fn(|i| u16::from_be_bytes([packet[8 + i*2], packet[8 + i*2 + 1]]));
|
||||
let dst_ip = std::array::from_fn(|i| u16::from_be_bytes([packet[24 + i*2], packet[24 + i*2 + 1]]));
|
||||
|
||||
let dst_port = Port::from_be_bytes([packet[42], packet[43]]);
|
||||
let dns;
|
||||
if dst_port == 53 { dns = true; } else { dns = false; };
|
||||
let v6 = PacketInfo::V6{
|
||||
src_ip,
|
||||
src_port: Port::from_be_bytes([packet[40], packet[41]]),
|
||||
dst_ip: <Ipv6>::try_from(&packet[24..40])?,
|
||||
dst_ip,
|
||||
dst_port,
|
||||
protocol: match packet[6] {
|
||||
6 => Protocol::TCP,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue