P
P
Pcap
Search…
⌃K

Introduction

Pcap provides a packet processing library for rapid development on top of JVM languages.

Hello Pcap!

"Hello pcap!" implementation in different JVM languages.
Java
Kotlin
Scala
Groovy
Clojure
JRuby
Jython
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()

Version History

Pcap is using semantic versioning: https://semver.org
Version
Latest Version
Release Date
Latest Release
1.0.0
1.0.7
2020-12-24
2021-03-12
1.2.0
1.2.2
2021-02-01
2021-03-20
1.3.0
1.3.4
2021-05-02
2021-11-15
1.4.0
1.4.2
2021-12-25
2022-09-13

Project Status

Supported platforms

  • Linux (Tested)
  • Mac OS (Tested)
  • Windows (Tested)
  • FreeBSD (Tested)
  • Other OSes that supported by both Libpcap and JNA (Untested).

Requirements

  • Java 7+
  • Libpcap for Unix or Npcap for Windows

Java module system with java 9+

Pcap can be used in modular java 9+ applications with specific module name listed below:
  • pcap-spi: pcap.spi
  • pcap-jdk7: pcap.jdk7
  • pcap-common: pcap.common
  • pcap-codec: pcap.codec

Disclimers

  • Every types, methods, or fields annotated with @Incubating might be changed or removed at any time.
  • Every types, methods, or fields annotated with @Incubating does not imply that the functionality being tested.
  • Calling the @Restricted method might crash your app if you use it incorrectly. Make sure you know what you're doing with it.
Last modified 2mo ago