Skip to content

Commit

Permalink
Handle dropped packet counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Sep 21, 2024
1 parent 08e67d6 commit 97abde7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct CaptureMetadata {
// Fields corresponding to PcapNG interface statistics.
pub start_time: Option<SystemTime>,
pub end_time: Option<SystemTime>,
pub dropped: Option<u64>,
}

/// Capture state shared between readers and writers.
Expand Down
6 changes: 6 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ where Source: Read
)
);
},
IsbIfDrop(pkts) => {
meta.dropped.replace(pkts);
},
_ => {}
};
}
Expand Down Expand Up @@ -467,6 +470,9 @@ fn stats_options(meta: &CaptureMetadata)
let mut opt = Vec::new();
option!(meta, opt, start_time, IsbStartTime, time_micros);
option!(meta, opt, end_time, IsbEndTime, time_micros);
if let Some(pkts) = meta.dropped {
opt.push(IsbIfDrop(pkts));
}
opt
}

Expand Down
18 changes: 11 additions & 7 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,13 +1215,11 @@ pub fn start_cynthion() -> Result<(), Error> {
for packet in stream_handle {
decoder.handle_raw_packet(&packet.bytes, packet.timestamp_ns)?;
}
decoder.handle_metadata(Box::new(
CaptureMetadata {
end_time: Some(SystemTime::now()),
.. Default::default()
}
));
decoder.finish()?;
let writer = decoder.finish()?;
writer.shared.metadata.update(|meta| {
meta.end_time = Some(SystemTime::now());
meta.dropped = Some(0);
});
Ok(())
};
std::thread::spawn(move || {
Expand Down Expand Up @@ -1316,6 +1314,12 @@ fn show_metadata() -> Result<(), Error> {
.unwrap_or(NONE.to_string());
add_field(row, name, &text);
}
add_field(row, "Packets dropped:",
&meta.dropped
.as_ref()
.map(|p| format!("{p}"))
.unwrap_or(NONE.to_string())
);
add_heading(row, "Comment:");
if let Some(text) = &meta.comment {
comment_buffer.set_text(text);
Expand Down

0 comments on commit 97abde7

Please sign in to comment.