- 论坛徽章:
- 0
|
我是一个比较菜的一个人,最近在研究使用jpcap抓包,使用jdk1.5做了一个简单的程序,但是编译通过了,运时时发现了如下一个错误。
C:\myjava>java getpkt
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d7cccc3, pid=2164, tid=3792
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_10-b03 mixed mode, sharing)
# Problematic frame:
# V [jvm.dll+0x9ccc3]
#
# An error report file with more information is saved as hs_err_pid2164.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
我写的代码如下:
import jpcap.*;
import jpcap.packet.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.io.*;
class pkthd implements PacketReceiver{
String len="";
String sport="";
String dport="";
String sip="";
String dip="";
String smac="";
String dmac="";
String[] col={"len","sport","dport","sip","dip","smac","dmac"};
DefaultTableModel dft=new DefaultTableModel(){
public boolean isCellEditable(int row,int colm){
return false;
}
};
pkthd(){
dft.setColumnIdentifiers(col);
}
public void receivePacket(Packet p){
len=Integer.toString(p.len);
EthernetPacket ethpkt;
ethpkt =(EthernetPacket)p.datalink;
smac="";
dmac="";
for(byte b:ethpkt.src_mac) smac=smac+Integer.toHexString(b&0xff);
for(byte b:ethpkt.dst_mac) dmac=dmac+Integer.toHexString(b&0xff);
IPPacket ippkt;
ippkt=(IPPacket) p;
dip=ippkt.dst_ip.toString();
sip=ippkt.src_ip.toString();
if((p instanceof TCPPacket)||(p instanceof UDPPacket)){
if(p instanceof TCPPacket){
TCPPacket tcppkt;
tcppkt=(TCPPacket) ippkt;
sport=Integer.toString(tcppkt.src_port);
dport=Integer.toString(tcppkt.dst_port);
}
else{
UDPPacket tcppkt;
tcppkt=(UDPPacket) ippkt;
sport=Integer.toString(tcppkt.src_port);
dport=Integer.toString(tcppkt.dst_port);
}
}
dft.addRow(new String[]{len,sport,dport,sip,dip,smac,dmac});
}
}
class getpkt{
public static void main(String args[])throws IOException{
pkthd ph=new pkthd();
NetworkInterface dev[]=JpcapCaptor.getDeviceList();
int devindex=1;
JpcapCaptor cator=JpcapCaptor.openDevice(dev[devindex],65535,true,20);
JFrame jf=new JFrame("Captor");
jf.setSize(400,600);
jf.setDefaultCloseOperation(3);
JTable jtb=new JTable(ph.dft);
JScrollPane jsp=new JScrollPane(jtb);
jf.getContentPane().setLayout(new BorderLayout());
jf.getContentPane().add(jsp);
jf.setVisible(true);
int f=cator.processPacket(20,ph);
System.out.println("The total packet is:"+f);
}
}
请高手指点一下,为什么会产生这样的错。 |
|