Java jnetpcap IndexOutOfBoundsEcxeption payload

时间:2014-11-01 13:13:05

标签: java indexoutofboundsexception payload jnetpcap

  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() );
                }
              }'

有时当我运行程序时,我得到IndexOutOfBoundsEcxeption in try "payload = packet.getHeader(new Payload());"我不知道为什么我会得到异常

1 个答案:

答案 0 :(得分:0)

我猜错误是因为if cond检查先前数据包的协议ID,这可能与您正在处理的有效负载不同。

替换以下逻辑

if(packet.hasHeader(Payload.ID)){

         try{
         payload = packet.getHeader(new Payload());
         }
         catch(Exception e)
         {
            System.err.println("ERROR"); 
         }

Payload pl = new Payload();

if(packet.hasHeader(pl))//这将检查并检索有效负载