[英]Java jnetpcap IndexOutOfBoundsEcxeption payload
if (packet.hasHeader(ip)) {
String str = FormatUtils.ip(ip.source());
if (packet.hasHeader(Payload.ID)) {
try{
payload = packet.getHeader(new Payload());
}
catch(Exception e)
{
System.err.println("ERROR");
}
if(payload!=null){
String pattern;
synchronized (MainThread.lockB){
pattern=MPSM.findpatt(payload.toString());
}
synchronized (MainThread.lockB){
smpsmCheckPattern(pattern, nameOfAdd, payload.toString() );
}
}'
sometimes when i run the programm i get IndexOutOfBoundsEcxeption in try "payload = packet.getHeader(new Payload());"
有时当我运行程序时,我
IndexOutOfBoundsEcxeption in try "payload = packet.getHeader(new Payload());"
得到IndexOutOfBoundsEcxeption in try "payload = packet.getHeader(new Payload());"
i dont know why i get the exception 我不知道为什么我会得到例外
i guess the error is because the if cond checks for the protocol id of a previous packet which might be different from the payload which you are processing now. 我猜这是因为if cond检查先前数据包的协议ID,这可能与您正在处理的有效负载不同。
Replace the below logic 替换以下逻辑
if (packet.hasHeader(Payload.ID)) { 如果(packet.hasHeader(Payload.ID)){
try{
payload = packet.getHeader(new Payload());
}
catch(Exception e)
{
System.err.println("ERROR");
}
with 与
Payload pl = new Payload(); 有效载荷pl =新的有效载荷();
if(packet.hasHeader(pl)) //this will check and retrieve the payload if(packet.hasHeader(pl))//这将检查并检索有效载荷
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.