Read packets from a capture file.
Read packets from the capture file that was created from the previous section.
public static void main(String[] _args) throws ErrorException {
var service = Service.Creator.create("PcapService");
try (var pcap = service.offline("savefile.pcap", new DefaultOfflineOptions())) {
try {
pcap.loop(
10,
(args, header, buffer) -> {
System.out.println("Args : " + args);
System.out.println("Header : " + header);
System.out.println("Packet : " + buffer);
},
"Hello pcap!");
} catch (BreakException e) {
System.err.println(e.getMessage());
} catch (ErrorException e) {
System.err.println(e.getMessage());
}
}
}
fun main() {
val service = Service.Creator.create("PcapService")
val pcap = service.offline("savefile.pcap", DefaultOfflineOptions())
try {
pcap.loop(
10,
{ args: String, header: PacketHeader, buffer: PacketBuffer ->
println("Args : $args")
println("Header : $header")
println("Packet : $buffer")
},
"Hello pcap!"
)
} catch (e: BreakException) {
System.err.println(e.message)
} catch (e: ErrorException) {
System.err.println(e.message)
}
pcap.close()
}
def main(_args: Array[String]): Unit = {
val service = Service.Creator.create("PcapService")
val pcap = service.offline("savefile.pcap", new DefaultOfflineOptions())
try pcap.loop(10, (args: String, header: PacketHeader, buffer: PacketBuffer) => {
println("Args : ", args)
println("Header : ", header)
println("Packet : ", buffer)
}, "Hello pcap!")
catch {
case e: BreakException =>
System.err.println(e.getMessage)
case e: ErrorException =>
System.err.println(e.getMessage)
}
pcap.close()
}
Last updated