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

Runing on the a linux service reports a null pointer exception

asdf101221 opened this issue · comments

I installed libcap in linux and runed pcap4j . but program report path is null point exception
so I fixed it by modifying the org/pcap4j/core/NativeMappings.java file details as follows:
45 line
static final File NPCAP_DIR =
Paths.get(System.getenv("SystemRoot"), "System32", "Npcap").toFile();

Because System.getenv("SystemRoot") is null when programmer runing on linux.
So I change the code as follows:
static File NPCAP_DIR;

static {
LOG.info("NPCAP_DIR: "+ NativeMappings.NPCAP_DIR);
String evn = System.getenv("SystemRoot");
LOG.info("NPCAP_DIR evn: "+ evn);
if(evn!=null) {
Path path = Paths.get(System.getenv("SystemRoot"), "System32", "Npcap");
if(path!=null ) {
LOG.info("NPCAP_DIR: "+ path.getFileName());
NPCAP_DIR = path.toFile();
}else {
LOG.info("NPCAP_DIR IS NULL");
}
}

}