Skip to content

Runing on the a linux service reports a null pointer exception #309

@asdf101221

Description

@asdf101221

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions