Capture statistics
Getting statistics about packets received and dropped in a live capture.
public static void main(String[] _args)
throws ErrorException, PermissionDeniedException, PromiscuousModePermissionDeniedException,
TimestampPrecisionNotSupportedException, RadioFrequencyModeNotSupportedException,
NoSuchDeviceException, ActivatedException, InterfaceNotUpException,
InterfaceNotSupportTimestampTypeException {
var service = Service.Creator.create("PcapService");
try (var pcap = service.live(service.interfaces(), new DefaultLiveOptions())) {
PacketHeader header = pcap.allocate(PacketHeader.class);
PacketBuffer buffer = pcap.allocate(PacketBuffer.class);
for (int i = 0; i < 10; i++) {
try {
pcap.nextEx(header, buffer);
System.out.println("Header : " + header);
System.out.println("Packet : " + buffer);
val stats = pcap.stats();
System.out.println("Stats : " + stats);
} catch (BreakException e) {
System.err.println(e.getMessage());
} catch (TimeoutException e) {
System.err.println(e.getMessage());
}
}
}
}
Last updated
Was this helpful?