use ihl to derive port bytes
This commit is contained in:
parent
da8e70f2e3
commit
50524cb5ae
2 changed files with 14 additions and 12 deletions
|
|
@ -52,13 +52,15 @@ pub fn sniff_raw_packets(packet: &Packet) -> SniffedPacket {
|
|||
let ver = packet[0] >> 4;
|
||||
match ver {
|
||||
4 => {
|
||||
let dst_port = Port::from_be_bytes([packet[22], packet[23]]);
|
||||
// Internet Header Length (IHL).
|
||||
let ihl = (packet[0] & 0x0F) as usize * 4;
|
||||
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[20], packet[21]]),
|
||||
src_port: Port::from_be_bytes([packet[ihl], packet[ihl+1]]),
|
||||
dst_ip: <Ipv4>::try_from(&packet[16..20])?,
|
||||
dst_port,
|
||||
protocol: match packet[9] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue