Skip to content

slytechs-repos/jnetpcap-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jNetPcap SDK

Java Maven Central License

The easiest way to get started with jNetPcap.

One dependency, everything included.


Installation

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

Latest Development Build (3.1.0-SNAPSHOT)

<repositories>
    <repository>
        <id>central-portal-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.1.0-SNAPSHOT</version>
    <type>pom</type>
</dependency>

What's Included

Module Description
jnetpcap-api High-level capture and protocol dissection API
jnetpcap-bindings Low-level libpcap FFM bindings (1:1 libpcap)
sdk-protocol-core Packet, Header, dissection framework
sdk-protocol-tcpip Ethernet, IPv4/IPv6, TCP, UDP, ICMP and more
sdk-protocol-web HTTP, TLS, QUIC, HTTP/2, HTTP/3
sdk-common Memory management, pooling, utilities

Quick Start

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

try (var pcap = NetPcap.openOffline("capture.pcap")) {
    Ip4 ip4 = new Ip4();
    Tcp tcp = new Tcp();

    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());
    });
}

No license calls required — the Community Edition activates automatically.

Run

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

Live Capture

try (var pcap = NetPcap.create("eth0")) {
    pcap.setSnaplen(65535)
        .setPromisc(true)
        .setTimeout(Duration.ofSeconds(1))
        .activate();

    pcap.setFilter("tcp port 443");

    Ip4 ip4 = new Ip4();
    pcap.loop(-1, packet -> {
        if (packet.hasHeader(ip4))
            System.out.println(ip4.src() + " -> " + ip4.dst());
    });
}

Optional Protocol Packs

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

Native Library Requirements

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

Gradle

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

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

Examples

See jnetpcap-examples for working examples covering:

  • Live capture and offline file reading
  • Protocol dissection (Ethernet, IP, TCP, HTTP, TLS)
  • BPF filtering
  • Packet dumping with PcapDumper
  • Pooled zero-allocation capture
  • Multi-threaded producer-consumer patterns
  • Interface enumeration

Documentation


License

Licensed under the Apache License, Version 2.0.

The Community Edition includes telemetry. For commercial licenses without telemetry, contact sales@slytechs.com.


Sly Technologies Inc. — High-performance network analysis solutions

About

The easiest way to get started with jNetPcap

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors