mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-19 08:45:16 +00:00
pcap: preserve capture and protocol source history
Port relevant PCAP implementation and regression snapshots from Craft Anything 43bd04745f42daefd9dea16756b13816fa7485a6.
This commit is contained in:
1 parent
a9acede958
commit
79a002518c
2 files changed
+34
-1
No files matched your search
@@ -716,7 +716,7 @@ fn ipv6(p: &[u8], d: &mut Decoded) {
|
||||
}
|
||||
|
||||
fn tcp_flags(f: u8) -> String {
|
||||
let names = [(0x02, "SYN"), (0x10, "ACK"), (0x01, "FIN"), (0x04, "RST"), (0x08, "PSH"), (0x20, "URG")];
|
||||
let names = [(0x02, "SYN"), (0x10, "ACK"), (0x01, "FIN"), (0x04, "RST"), (0x08, "PSH"), (0x20, "URG"), (0x40, "ECE"), (0x80, "CWR")];
|
||||
names.iter().filter(|(b, _)| f & b != 0).map(|(_, n)| *n).collect::<Vec<_>>().join(",")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
use craft_anything_formats::pcap::decode;
|
||||
|
||||
/// Decode a raw IPv4 packet with a TCP header and the specified control bits.
|
||||
fn flags_on_wire(bits: u8) -> String {
|
||||
let mut packet = [0u8; 40];
|
||||
packet[0] = 0x45;
|
||||
packet[2..4].copy_from_slice(&40u16.to_be_bytes());
|
||||
packet[8] = 64;
|
||||
packet[9] = 6;
|
||||
packet[20..24].copy_from_slice(&[0xc0, 0, 0x01, 0xbb]);
|
||||
packet[32] = 0x50;
|
||||
packet[33] = bits;
|
||||
decode(228, &packet).transport.unwrap().tcp_flags.unwrap()
|
||||
}
|
||||
|
||||
/// An ECN-capable SYN shows both classic ECN flags.
|
||||
#[test]
|
||||
fn reports_ecn_setup_on_syn() {
|
||||
assert_eq!(flags_on_wire(0xc2), "SYN,ECE,CWR");
|
||||
}
|
||||
|
||||
/// The receiver and sender can signal ECE and CWR independently on ACKs.
|
||||
#[test]
|
||||
fn distinguishes_ecn_echo_and_window_reduction() {
|
||||
assert_eq!(flags_on_wire(0x50), "ACK,ECE");
|
||||
assert_eq!(flags_on_wire(0x90), "ACK,CWR");
|
||||
}
|
||||
|
||||
/// Existing non-ECN packets keep their flag strings.
|
||||
#[test]
|
||||
fn keeps_ordinary_ack_flags() {
|
||||
assert_eq!(flags_on_wire(0x12), "SYN,ACK");
|
||||
}
|
||||
Reference in new issue
Block a user