summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzedddie <rust@zedddie.rs>2026-03-23 20:23:41 +0100
committertuturuu <zedddiezxc@gmail.com>2026-03-23 20:23:41 +0100
commiteedb2c5d02fa5b124c9d859c973939880a84cb76 (patch)
treee20d68cc8b760de693c6f17aefaec91236866639 /src
parentd0513bec6a51ee5d27cc90003945185438eca4a6 (diff)
wip&fixme
Diffstat (limited to 'src')
-rw-r--r--src/sniffing/headers.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/sniffing/headers.rs b/src/sniffing/headers.rs
index 4514e3b..d49d402 100644
--- a/src/sniffing/headers.rs
+++ b/src/sniffing/headers.rs
@@ -18,7 +18,7 @@ pub enum IpVersion {
V6
}
type Ipv4 = [u8; 4];
-type Ipv6 = [u8; 16];
+type Ipv6 = [u16; 8];
type Port = u16;
#[derive(Debug, PartialEq)]
pub enum PacketInfo {
@@ -128,7 +128,6 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
let dst_port = Port::from_be_bytes([packet[ihl+2], packet[ihl+3]]);
let dns;
if dst_port == 53 { dns = true; } else { dns = false; };
- // FIXME: hardcoded IPv4 port offset
let v4 = PacketInfo::V4{
src_ip: <Ipv4>::try_from(&packet[12..16])?,
src_port: Port::from_be_bytes([packet[ihl], packet[ihl+1]]),
@@ -151,11 +150,14 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
Ok(v4)
},
6 => {
- let dst_port = Port::from_be_bytes([packet[22], packet[23]]);
+ // 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]));
+ 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: <Ipv6>::try_from(&packet[8..24])?,
+ src_ip,
src_port: Port::from_be_bytes([packet[40], packet[41]]),
dst_ip: <Ipv6>::try_from(&packet[24..40])?,
dst_port,