Git Product home page Git Product logo

pcap's Introduction

Pcap Project

Maven Central javadoc

Bugs Coverage Duplicated Lines (%) Lines of Code Maintainability Rating Reliability Rating Security Rating Vulnerabilities

Quality Gate Status Code Smells Technical Debt

About this project

Provides JVM network packet processing library for rapid development.

Documentation

License

Pcap is primarily distributed under the terms of both the MIT License and the Apache License (Version 2.0).

SPDX-License-Identifier: MIT OR Apache-2.0

pcap's People

Contributors

andrewauclair avatar ardikars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pcap's Issues

Null Addresses on CentOS 7

Not sure what I'm doing wrong here. I am using Ardikars Pcap 1.4.2 on CentOS 7 with libpcap installed and when I print out the devices everything is null, even if I'm running as admin.

implementation group: 'com.ardikars.pcap', name: 'pcap-jdk7', version: '1.4.2'

libpcap 1.5.3-13.el7_9.x86_64

Null address on Linux

Issue

All address is null on linux.

Version

pcap-api 0.0.18 (Unstable)

OS Version

Linux 5.4.0-kali4-amd64 #1 SMP Debian 5.4.19-1kali1 (2020-02-17) x86_64 GNU/Linux

Pcap version

libpcap version 1.9.1 (with TPACKET_V3)

Java version

openjdk version "14-panama" 2020-03-17
OpenJDK Runtime Environment (build 14-panama+1-15)
OpenJDK 64-Bit Server VM (build 14-panama+1-15, mixed mode, sharing)

Step to reproduce

    for (Interface iface : Pcaps.lookupInterfaces()) {
      LOGGER.info(iface.name());
      LOGGER.info(iface.description());
      LOGGER.info(String.valueOf(iface.flags()));
      if (Objects.nonNull(iface.addresses())) {
        for (Address address : iface.addresses()) {
          LOGGER.info("\t{}", address.address());
          LOGGER.info("\t{}", address.netmask());
          LOGGER.info("\t{}", address.broadcast());
          LOGGER.info("\t{}", address.destination());
        }
      }
    }

The library doesn't support Filter having spaces

Hi.. I am trying to write a packet capture which captures http traffic. This is how my program looks like.

DefaultLiveOptions liveOptions = new DefaultLiveOptions(); liveOptions.promiscuous(false).timeout(readTimeoutMillis).bufferSize(bufferSize) .snapshotLength(snapLength); StringBuilder sbBpfFilter = new StringBuilder("tcp port ").append(80).append(" or ").append(443).append(" and dst ").append(defaultInterfaceAddress.getHostAddress()); String bpfFilter = sbBpfFilter.toString(); pcapHandle = pcapService.live(pcapNetworkInterface, liveOptions); pcapHandle.setNonBlock(true); pcapHandle.setFilter(bpfFilter, true); // Start capturing packets in an infinite loop pcapHandle.loop(-1, new MyPacketHandler(pcapHandle), "Hello pcap!");

The program throws exception saying the filter is empty. But if you look at the logger its not empty. It does have spaces.
23:43:51.818 [PacketSnifferThread] INFO c.q.k.h.p.PerformancePacketSniffer - BPF filter:tcp port 9090 or 9443 and dst 192.168.4.27 pcap_can_set_frmon: Function doesn't exist. pcap_can_set_rfmon: pcap_statustostr: Function doesn't exist. 23:43:51.836 [PacketSnifferThread] ERROR c.q.k.h.p.PerformancePacketSniffer - Exception starting packet capture java.lang.IllegalArgumentException: filter: null (expected: filter != null && notBlank(filter)) at pcap.jdk7.internal.DefaultPcap.setFilter(DefaultPcap.java:74) ~[pcap-jdk7-0.8.3.jar:na] at com.qumu.kodiak.http.perf.PerformancePacketSniffer$PacketSnifferRunnable.run(PerformancePacketSniffer.java:154) ~[classes/:na] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_201] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_201] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_201] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_201] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_201] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_201] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]
Please help.

Bug in IPV4 header checksum calculation

If you have an entire Ethernet packet, and you use the codec features like this:

Ethernet ethernet = buffer.cast(Ethernet.class);
Ip4 ip4 = buffer.readerIndex(ethernet.size()).cast(Ip4.class);
ip4.checksum(ip4.calculateChecksum());

The wrong checksum is calculated. That is because the accumulation -= buffer.getShort(10) & 0xFFFF; in Ip4::calculateChecksum is trying to remove the preexisting checksum from checksum calculation (which is the correct thing to do) but the address of the checksum it is trying to remove, 10, is only correct when the Ip4 was constructed with offset zero.

If the Ip4 header is part of a larger buffer, in my case an Ethernet packet, then it is grabbing some arbitrary bytes from the middle of the MAC address in the ethernet header.

  public int calculateChecksum() {
    int accumulation = Checksum.sum(buffer, offset, ihl() << 2);
    accumulation -= buffer.getShort(10) & 0xFFFF;
    accumulation = (accumulation >> 16 & 0xFFFF) + (accumulation & 0xFFFF);
    return (~accumulation & 0xFFFF);
  }

The correct code would be

accumulation -= buffer.getShort(headerChecksum) & 0xFFFF;

Support Npcap native mode on Windows

We keep having issues with npcap being reinstalled without Winpcap Compatibility mode (for example, by installing Wireshark) and our software not working with it because ardikars pcap requires Winpcap Compatiblity mode.

See pcap4j for how they supported npcap native mode. kaitoy/pcap4j#87

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.