"Hello pcap!" implementation in different JVM languages.
var service = Service.Creator.create("PcapService");
try (var pcap = service.live(service.interfaces(), new DefaultLiveOptions())) {
pcap.loop(10, (args, header, buffer) -> {
System.out.println("Args : " + args);
System.out.println("Header : " + header);
System.out.println("Packet : " + buffer);
}, "Hello pcap!");
}
val service = Service.Creator.create("PcapService")
val pcap = service.live(service.interfaces(), DefaultLiveOptions())
pcap.loop(10, { args, header, buffer ->
println("Args : $args")
println("Header : $header")
println("Packet : $buffer")
}, "Hello pcap!")
pcap.close()
val service = Service.Creator.create("PcapService")
val pcap = service.live(service.interfaces(), new DefaultLiveOptions())
pcap.loop(10, (args: String, header: PacketHeader, buffer: PacketBuffer) => {
println("Args : ", args)
println("Header : ", header)
println("Packet : ", buffer)
}, "Hello pcap!")
pcap.close()
def service = Service.Creator.create("PcapService")
def pcap = service.live(service.interfaces(), new DefaultLiveOptions())
pcap.loop(10, { args, header, buffer ->
println("Args : " + args)
println("Header : " + header)
println("Packet : " + buffer)
}, "Hello pcap!");
pcap.close()
(def service (. Service$Creator (create "PcapService")))
(def pcap (.live service (.interfaces service) (DefaultLiveOptions.)))
(def handler (reify PacketHandler (gotPacket [this args header buffer]
(println "Args : " args)
(println "Header : " header)
(println "Buffer : " buffer))))
(.loop pcap 10 handler "Hello pcap!")
(.close pcap))
class Callback
def gotPacket(args, header, buffer)
puts "Args : " + args
puts "Header : " + header.toString
puts "Buffer : " + buffer.toString
end
end
service = Service::Creator.create('PcapService')
pcap = service.live(service.interfaces(), DefaultLiveOptions.new)
pcap.loop(10, Callback.new, "Hello pcap!")
pcap.close()
class Callback(PacketHandler):
def gotPacket(self, args, hdr, buf):
print("Args : ", args)
print("Header : ", hdr)
print("Buffer : ", buf)
service = DefaultService()
pcap = service.live(service.interfaces(), DefaultLiveOptions())
pcap.loop(10, Callback(), "Hello pcap!")
pcap.close()
Java module system with java 9+
Pcap can be used in modular java 9+ applications with specific module name listed below: