Skip to content

Commit

Permalink
pcap-info: print unknown options as hex, not UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
pc-anssi committed Sep 24, 2024
1 parent 831433b commit 14c57e4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pcap-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ fn pretty_print_shb_option(code: OptionCode, value: &[u8]) {
println!("User Application: {}", s);
}
OptionCode(_) => {
let s = str::from_utf8(value).unwrap_or("<Invalid UTF-8>");
println!("Option {}: {}", code, s);
print!("Option {}: ", code);
print_hex_dump(value, 32);
}
}
}
Expand Down Expand Up @@ -269,8 +269,18 @@ fn pretty_print_idb_option(code: OptionCode, value: &[u8]) {
println!("Operating System: {}", s);
}
OptionCode(_) => {
let s = str::from_utf8(value).unwrap_or("<Invalid UTF-8>");
println!("Option {}: {}", code, s);
print!("Option {}: ", code);
print_hex_dump(value, 32);
}
}
}

fn print_hex_dump(bytes: &[u8], max_len: usize) {
for &b in bytes.iter().take(max_len) {
print!("{:02X} ", b);
}
if bytes.len() > max_len {
print!("... <continued>");
}
println!();
}

0 comments on commit 14c57e4

Please sign in to comment.