Created
October 22, 2019 10:57
-
-
Save ian-p-cooke/baccf3337295d8872ad83e6ccb58d9a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// So this code looks wrong to me. What the correct way to "switch" on ethertype to get the next layer? | |
let packet = // some bytes from a PCAP file | |
let ether = EthernetPacket::new(&packet).expect("could not parse Ethernet frame"); | |
// I don't know if the next line is valid; what if there's no Vlan layer and it doesn't parse ether.payload()? | |
let vlan = VlanPacket::new(ether.payload()).expect("could not parse Vlan frame"); | |
let payload = if ether.get_ethertype() == ethernet::EtherTypes::Vlan { | |
vlan.payload() | |
} else { | |
ether.payload() | |
}; | |
let ip = Ipv4Packet::new(payload).expect("could not parse Ipv4 frame"); | |
let udp = UdpPacket::new(ip.payload()).expect("could not parse Udp frame"); | |
let data = udp.payload(); | |
// process `data` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment