Skip to content

slytechs-repos/jnetpcap-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jNetPcap SDK

Java Maven Central License

The easiest way to get started with jNetPcap.

One dependency, everything included.


Installation (Stable Release)

When the stable 3.0.0 is released:

<dependency>
    <groupId>com.slytechs.sdk</groupId>
    <artifactId>jnetpcap-sdk</artifactId>
    <version>3.0.0</version>
</dependency>

Current Development Version (3.0.0-SNAPSHOT)

To use the latest development build (recommended for early adopters):

<repositories>
    <repository>
        <id>sonatype-snapshots</id>
        <url>https://central.sonatype.com/repository/maven-snapshots/</url>
        <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
</repositories>

<dependency>
    <groupId>com.slytechs.sdk</groupId>
    <artifactId>jnetpcap-sdk</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>

That's it.


What's Included

Module Description
jnetpcap-api High-level capture and analysis API
jnetpcap-bindings Low-level libpcap FFM bindings
sdk-protocol-tcpip Ethernet, IPv4/6, TCP, UDP, VLAN, MPLS, IPsec
sdk-protocol-core Protocol dissection framework
sdk-common Memory management and utilities

Quick Start

import com.slytechs.jnet.jnetpcap.api.NetPcap;
import com.slytechs.sdk.protocol.tcpip.ip.Ip4;
import com.slytechs.sdk.protocol.tcpip.tcp.Tcp;

public class CaptureExample {
    public static void main(String[] args) throws PcapException {
        // Activate the community license (required, internet connection needed)
        NetPcap.activateLicense();
        
        // Pre-allocate headers for zero-allocation capture
        Ip4 ip4 = new Ip4();
        Tcp tcp = new Tcp();
        
        try (var pcap = NetPcap.openOffline("capture.pcap")) {
            
            pcap.dispatch(100, packet -> {
                
                if (packet.hasHeader(ip4)) {
                    System.out.printf("IP: %s -> %s%n", ip4.src(), ip4.dst());
                }
                
                if (packet.hasHeader(tcp)) {
                    System.out.printf("TCP: %d -> %d%n", tcp.srcPort(), tcp.dstPort());
                }
            });
        }
    }
}

JVM Arguments

jNetPcap uses the Java Foreign Function & Memory (FFM) API for native libpcap access. Add these JVM arguments when running your application:

java --enable-native-access=com.slytechs.sdk.jnetpcap,com.slytechs.sdk.common -jar myapp.jar

For Maven exec plugin:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>--enable-native-access=com.slytechs.sdk.jnetpcap,com.slytechs.sdk.common</argument>
            <argument>-classpath</argument>
            <classpath/>
            <argument>com.example.MyApp</argument>
        </arguments>
    </configuration>
</plugin>

License Activation

The jNetPcap SDK includes a free unlimited Community Edition license. To use it:

  1. Call NetPcap.activateLicense() once at application startup
  2. Internet connectivity is required for activation
  3. No registration or API keys needed
public static void main(String[] args) throws PcapException {
    // Required: Activate the community license before any capture operations
    NetPcap.activateLicense();
    
    // Now use jNetPcap normally
    try (var pcap = NetPcap.openOffline("capture.pcap")) {
        pcap.loop(-1, packet -> System.out.println(packet));
    }
}

The Community Edition is licensed under Apache 2.0 with telemetry. For commercial licenses without telemetry, contact [email protected].


Optional Protocol Packs

Need more protocols? Add them (same version and repository rules apply):

<!-- Web protocols: HTTP, TLS, DNS, QUIC, WebSocket -->
<dependency>
    <groupId>com.slytechs.sdk</groupId>
    <artifactId>sdk-protocol-web</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>

<!-- Infrastructure: BGP, OSPF, STP, VRRP, LACP, LLDP -->
<dependency>
    <groupId>com.slytechs.sdk</groupId>
    <artifactId>sdk-protocol-infra</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>

Native Library Requirements

Platform Library Installation
Linux libpcap apt install libpcap-dev
macOS libpcap Pre-installed
Windows Npcap npcap.com

Examples

See the jnetpcap-examples repository for complete working examples:

  • Live capture with BPF filters
  • Offline pcap/pcapng file reading
  • Protocol dissection (Ethernet, IPv4/6, TCP, UDP)
  • Packet persistence and pooling
  • Multi-threaded capture patterns
  • Writing packets to files

Documentation


Gradle

repositories {
    mavenCentral()
    maven { url 'https://central.sonatype.com/repository/maven-snapshots/' }
}

dependencies {
    implementation 'com.slytechs.sdk:jnetpcap-sdk:3.0.0-SNAPSHOT'
}

License

Licensed under Apache License v2.0. See LICENSE for details.


Sly Technologies Inc. - High-performance network analysis solutions

Website: www.slytechs.com

About

The easiest way to get started with jNetPcap

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors