Java Jpcap破坏JVM

Java Jpcap破坏JVM,java,jvm,java-native-interface,jpcap,jvm-crash,Java,Jvm,Java Native Interface,Jpcap,Jvm Crash,我编写了以下程序,旨在将所有网络设备流量转储到一个文件中。我知道问题涉及到JpcapWriter的使用。为什么我会收到下面显示的错误消息 import jpcap.*; import jpcap.packet.*; public class dumptraffic { private static final int maxPackets = 100; public static void main(String args[]) { try

我编写了以下程序,旨在将所有网络设备流量转储到一个文件中。我知道问题涉及到JpcapWriter的使用。为什么我会收到下面显示的错误消息

import jpcap.*;
import jpcap.packet.*;

public class dumptraffic
{
    private static final int maxPackets = 100;

    public static void main(String args[])
    {
        try
        {
            NetworkInterface[] devices = JpcapCaptor.getDeviceList();

            if (args.length != 1)
            {
                System.out.println("You must enter a device number.");

                int i = 0;
                for (NetworkInterface device : devices)
                    System.out.println((i++) + ": " + device.name);

                return;
            }

            JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[Integer.parseInt(args[0].trim())], 2000, false, 20);
            JpcapWriter writer = JpcapWriter.openDumpFile(jpcap, "dump.pcap");

            for (int i = 0; i < maxPackets; i++)
                writer.writePacket(jpcap.getPacket());

            writer.close();

            System.out.println("Recorded packets to the file \"dump.pcap\"");
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }

}

我没有办法解决你的问题,但是你可以在谷歌群组上找到一个

在浏览这些消息(关键词“jvm崩溃”)时,我注意到有一条消息说问题出在调用参数错误的方法上。因此,您可以尝试再次检查代码是否正确使用了API


我不会将此报告给Sun/Oracle。崩溃转储中的证据表明某个东西在使用JNI时出现了错误。

您是以root还是m$等效身份运行它?在网络接口上随意收集数据包需要操作系统提供一些额外的特权

在for循环中使用此语句

  if(captor.getPacket()==null || captor.getPacket()==Packet.EOF) break;
关键是:

# The crash happened outside the Java Virtual Machine in native code.
也就是说,
jpcap
库使用本机代码,而本机代码是错误的。因此,这是
jpcap
库中的错误,而不是JVM中的错误。发件人:

现在,如果您愿意,您可以尝试通过在GDB中运行整个程序来调试segfault

不过。注意到

jpcap utilizes libpcap, a widely deployed shared-library for capturing 
user-level packets. libpcap must be installed on your system in order 
to use jpcap.

在文档中,考虑到SEGFULTS的一个常见原因是缺少共享库,我怀疑您的系统上没有安装
pcap
库。

将其报告给Sun,err Oracle。。。向jpcap指南提交一个bug。它自2007年以来就没有发布过,所以很可能您遇到了一个相当严重的bug…如果您不解决它,那么您可以查看一下
Internally, jpcap implements bindings to the libpcap system library 
through JNI (the Java Native Interface).
jpcap utilizes libpcap, a widely deployed shared-library for capturing 
user-level packets. libpcap must be installed on your system in order 
to use jpcap.