mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-05-27 01:54:46 -07:00
feat(pcap): add operating system kernel name and release
Display the uname sysname and release as the OS option in the pcap Section
Header Block, falling back on just the std::env::consts::OS name ("linux") in
the case of runtime errors.
Co-authored-by: Nat Budin <natbudin@gmail.com>
This commit is contained in:
committed by
Will Greenberg
parent
5ae186bc73
commit
09d35ccec7
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1694,6 +1694,7 @@ dependencies = [
|
||||
"futures-core",
|
||||
"libc",
|
||||
"log",
|
||||
"nix",
|
||||
"pcap-file-tokio",
|
||||
"serde",
|
||||
"telcom-parser",
|
||||
|
||||
@@ -17,6 +17,7 @@ deku = { version = "0.16.0", features = ["logging"] }
|
||||
env_logger = "0.10.1"
|
||||
libc = "0.2.150"
|
||||
log = "0.4.20"
|
||||
nix = { version = "0.29.0", features = ["feature"] }
|
||||
pcap-file-tokio = "0.1.0"
|
||||
thiserror = "1.0.50"
|
||||
telcom-parser = { path = "../telcom-parser" }
|
||||
|
||||
@@ -7,11 +7,13 @@ use tokio::io::AsyncWrite;
|
||||
use std::borrow::Cow;
|
||||
use chrono::prelude::*;
|
||||
use deku::prelude::*;
|
||||
use nix::sys::utsname::uname;
|
||||
use pcap_file_tokio::pcapng::blocks::enhanced_packet::EnhancedPacketBlock;
|
||||
use pcap_file_tokio::pcapng::blocks::interface_description::InterfaceDescriptionBlock;
|
||||
use pcap_file_tokio::pcapng::blocks::section_header::{SectionHeaderBlock, SectionHeaderOption};
|
||||
use pcap_file_tokio::pcapng::PcapNgWriter;
|
||||
use pcap_file_tokio::{Endianness, PcapError};
|
||||
use std::env::consts::OS;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -61,17 +63,25 @@ struct UdpHeader {
|
||||
|
||||
impl<T> GsmtapPcapWriter<T> where T: AsyncWrite + Unpin + Send {
|
||||
pub async fn new(writer: T) -> Result<Self, GsmtapPcapError> {
|
||||
let package = concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION"));
|
||||
let package = format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||
let application = SectionHeaderOption::UserApplication(Cow::from(package));
|
||||
let operating_system = match uname() {
|
||||
Ok(utsname) => format!(
|
||||
"{} {}",
|
||||
utsname.sysname().to_string_lossy(),
|
||||
utsname.release().to_string_lossy()
|
||||
),
|
||||
Err(_) => OS.to_owned(),
|
||||
};
|
||||
let os = SectionHeaderOption::OS(Cow::from(operating_system));
|
||||
let section = SectionHeaderBlock {
|
||||
endianness: Endianness::Big,
|
||||
major_version: 1,
|
||||
minor_version: 0,
|
||||
section_length: -1,
|
||||
options: vec![application],
|
||||
options: vec![os, application],
|
||||
};
|
||||
let writer = PcapNgWriter::with_section_header(writer, section).await?;
|
||||
|
||||
Ok(GsmtapPcapWriter { writer, ip_id: 0 })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user