-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Welcome to the jnetpcap-sdk wiki!
This guide will help you get started with jnetpcap, including installation using Maven and basic usage examples.
jNetPcap provides two versions to accommodate different JDK environments:
When using JDK 21 LTS, you'll need to enable preview features for specific modules:
javac --enable-preview --release 21
Add the following to your pom.xml
for JDK 21 support:
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
-
jnetruntime-api
: Requires --enable-preview -
jnetpcap-wrapper
: Requires --enable-preview - All other modules: Standard JDK 21 compilation
JDK 22 users can use jNetPcap without preview features:
<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<maven.compiler.release>22</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
</plugins>
</build>
- All modules: Standard JDK 22 compilation (no special options required)
When running applications with JDK 21:
# For applications using jnetruntime-api or jnetpcap-wrapper
java --enable-preview -jar your-application.jar
# For applications using only other modules
java -jar your-application.jar
When running applications with JDK 22:
java -jar your-application.jar
-
JDK 21 LTS Version
- Choose this if you need long-term support
- Acceptable if preview features are not a concern
- Required configuration is more complex
-
JDK 22 Version
- Choose this for simplified configuration
- No preview features required
- Latest Java features available
- Shorter support lifecycle
[Previous Installation section and rest of the content remains the same...]
To use jnetpcap in your project, you'll need to add the appropriate dependencies to your pom.xml
file.
First, add the core protocol pack SDK parent:
<parent>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-sdk-parent</artifactId>
<version>0.10.0-SNAPSHOT</version>
</parent>
Then add the protocol pack API dependency:
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-api</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
Depending on your needs, you can add additional protocol packs. Each pack provides support for specific protocols:
<!-- Core Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-core</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- VoIP Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-voip</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- Web Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-web</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- IoT Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-iot</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- Telco Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-telco</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- Database Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-database</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- Microsoft Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-microsoft</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- LTE Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-lte</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- 3G Protocol Pack -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-3g</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
Choose the protocol packs based on the protocols you need to work with. For example:
- If you're working with VoIP applications, include the
protocol-pack-voip
- For web applications, include the
protocol-pack-web
- For telecom applications, include the
protocol-pack-telco
- For database protocol analysis, include the
protocol-pack-database
Here's a complete example of a pom.xml
file for a basic jnetpcap project:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-sdk-parent</artifactId>
<version>0.10.0-SNAPSHOT</version>
</parent>
<artifactId>my-packet-analyzer</artifactId>
<version>1.0-SNAPSHOT</version>
<name>My Packet Analyzer</name>
<dependencies>
<!-- Core Protocol Pack API -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-api</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
<!-- Add specific protocol packs as needed -->
<dependency>
<groupId>com.slytechs.jnet.protocol</groupId>
<artifactId>protocol-pack-core</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
After adding the dependencies, you can start using jnetpcap in your code:
import com.slytechs.jnet.protocol.NetPcap;
import com.slytechs.jnet.protocol.Packet;
public class BasicCapture {
public static void main(String[] args) {
NetPcap pcap = NetPcap.openOffline("capture.pcap");
Packet packet = new Packet();
while (pcap.nextEx(packet)) {
System.out.println("Packet length: " + packet.length());
}
pcap.close();
}
}