Skip to content

slytechs-repos/jnetpcap-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Sonatype Nexus (Snapshots)

jNetPcap Wrapper

Unlock Network Packet Analysis in Java with jNetPcap Wrapper.

jNetPcap Wrapper is a libpcap Java library. This is the version 2 release of the popular jNetPcap library, originally hosted on [SourceForge.net][sf.net].


Table of Contents

  1. Overview
  2. API Diagram
  3. Documentation
  4. Where are the protocols found in v1?
  5. Examples
  6. Dependencies
  7. Installation
  8. Contact
  9. Compatibility with jNetPcap Version 1
  10. Git Branches
  11. Javadocs API Documentation

Overview

Harness the power of libpcap within your Java applications using jNetPcap Wrapper, a bridge granting seamless access to low-level network monitoring capabilities.

Key Features:

  • Capture and Analyze Network Traffic: Real-time packet interception for detailed analysis.
  • Streamlined Integration: Easily incorporate the library via Maven or manual classpath addition.
  • Intuitive Java API: User-friendly Java interface for network data handling.
  • Packet Capture and Handling: Utilize the Pcap class for interface monitoring and PcapPacketHandler for efficient packet processing.
  • Precise Packet Filtering: Apply filters for targeted packet capture.

API Diagram

graph TD
    A[Java Application] --> B[jnetpcap-wrapper]
    B --> C[Panama/JEP-424 Foreign Function & Memory API]
    C --> D[Libpcap / WinPcap / Npcap]
    D --> E[Operating System]
    E --> F[Network Drivers]
    F --> G[Network Interface Cards]
Loading

Documentation

  • Wiki pages: Comprehensive user guides and examples.
  • Javadocs: Detailed API documentation.

Where are the protocols found in v1?

Protocol support from version 1 is now part of jnetpcap-sdk, extending the basic wrapper's functionality.


Examples

Capture a Live Packet

void main() throws PcapException {
    List<PcapIf> devices = Pcap.findAllDevs();
    try (Pcap pcap = Pcap.create(devices.get(0))) {
        pcap.activate();
        pcap.loop(1, (String msg, PcapHeader header, byte[] packet) -> {
            System.out.println(msg);
        }, "Capture Example");
    }
}

Transmit a Packet With Data-Link Header

void main() throws PcapException {
    String rawPacket = "0026622f4787...";
    byte[] packetBytes = PcapUtils.parseHexString(rawPacket);
    List<PcapIf> devices = Pcap.findAllDevs();
    try (Pcap pcap = Pcap.create(devices.get(0))) {
        pcap.activate();
        pcap.sendPacket(packetBytes);
    }
}

Statistics Snapshots

void main() throws PcapException, InterruptedException {
    List<PcapIf> devices = Pcap.findAllDevs();
    try (Pcap pcap = Pcap.create(devices.get(0))) {
        pcap.activate();
        for (int i = 0; i < 5; i++) {
            System.out.println(pcap.stats());
            Thread.sleep(1000);
        }
    }
}

How To Run The Examples

Command-line Arguments:

  • Linux: -Djava.library.path=/usr/lib/... --enable-native-access=org.jnetpcap --enable-preview
  • Windows: -Djava.library.path=C:\Windows\... --enable-native-access=org.jnetpcap --enable-preview

Dependencies

Java Dependencies

No external dependencies apart from standard Java modules.

Native Library Dependencies

Requires libpcap, [Npcap][npcap], or [WinPcap][winpcap].


Installation

Maven Artifact Config

Use the latest version variable in your pom.xml for easy updates:

<properties>
    <jnetpcap.version>LATEST</jnetpcap.version>
</properties>

<dependency>
    <groupId>com.slytechs.jnet.jnetpcap</groupId>
    <artifactId>jnetpcap-wrapper</artifactId>
    <version>${jnetpcap.version}</version>
</dependency>

Using Latest SNAPSHOT Releases

Add this repository:

<repository>
    <id>sonatype-snapshots</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>

Download Release Package

Latest release: download link


Contact

  • Email: sales@slytechs.com

Compatibility with jNetPcap Version 1

Details in the Wiki.


Git Branches

Follows a standard branching model.


Javadocs API Documentation

The Javadocs are automatically generated and deployed to the gh-pages branch for easy reference. Access the Javadocs here