0
public void receivePacket(Packet packet) { 
for (byte b : ((TCPPacket)packet).option ) 

        { 
                 str += Integer.toHexString(b & 0xff) + ":"; 
                System.out.print(Integer.toHexString(b & 0xff) + ":"); 
        } 

    //if byte has  kind=8 and length=10, that means it has TCP Timestamp Option enabled 

    if(Pattern.matches("(.*)8:a(.*)", str)) 
        { 
                int tsval=0,tsecr=0; 
                int i = str.indexOf("8:a:"); 
                String tmp = str.substring(i+4); 

        for(int lp =1; lp<=3;lp++) 
            { 
                tmp=tmp.replaceFirst(":",""); 
            } 
        tsval = java.lang.Integer.parseInt(tmp.substring(0,tmp.indexOf(":")),16); 

        tmp = tmp.substring(tmp.indexOf(":")+1); 
        for(int lp =1; lp<=3;lp++) 
            { 
                tmp=tmp.replaceFirst(":",""); 
            } 
        if(tmp.indexOf(":")!=-1) 
            tsecr = java.lang.Integer.parseInt(tmp.substring(0,tmp.indexOf(":")),16); 
        else 
            tsecr = java.lang.Integer.parseInt(tmp.substring(0,16)); 
            System.out.println("\tTSval: "+tsval + "\tTSecr: "+tsecr); 

        } }     

i have found this solution online for filtering the timestamp of a tcp packet but its giving me an error on str ("cannot find variable str") can anyone help ?

4

1 回答 1

0

许多这些变量是您从中获取的类的字段。您最好尝试了解该类的工作原理,然后从头开始编写它,而不是尝试修改他们的代码。

于 2012-12-03T19:54:41.983 回答