kaitoy / pcap4j

A Java library for capturing, crafting, and sending packets.

Home Page:https://www.pcap4j.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Linux os][Windows "System32" Path.get] crash on init

freedom1b2830 opened this issue · comments

Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.pcap4j.core.Pcaps.findAllDevs(Pcaps.java:56)
	at org.pcap4j.util.NifSelector.selectNetworkInterface(NifSelector.java:34)
	at priv.Priv.getNetworkDevice(Priv.java:16)
	at priv.Priv.main(Priv.java:21)
Caused by: java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:208)
	at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:263)
	at java.base/java.nio.file.Path.of(Path.java:147)
	at java.base/java.nio.file.Paths.get(Paths.java:69)
	at org.pcap4j.core.NativeMappings.<clinit>(NativeMappings.java:46)
	... 4 more

Exception at line:

 static final File NPCAP_DIR =
      Paths.get(System.getenv("SystemRoot"), "System32", "Npcap").toFile();

os:

Linux archlinux 5.17.5-arch1-1 #1 SMP PREEMPT Wed, 27 Apr 2022 20:56:11 +0000 x86_64 GNU/Linux
lib32-libpcap 1.10.1-1
libpcap 1.10.1-2
jdk17-openjdk 17.0.3.u7-2
jdk-openjdk 18.0.1.u10-1

What version of pcap4j are you using?

I can replicate the problem using V2 and newer jvm's as Paths.get() has become stricter over time with the first Param no longer having null allowed.

Obviously the issue can be worked around on your Linux by setting the SytemRoot envar to anything prior to running your app.

I also have fixed it in V2 code in my fork, however unclear as to how v1 and V2 relate in this project as V2 not a separate branch with v1 being patched after V2 code was started

I realized that I was using the unstable version 2.0.0-alpha.X