Jnetpcap UDP重新计算校验和

时间:2015-01-10 09:42:01

标签: udp jnetpcap

我试图在我改变IPD目的地的数据包上重新计算UDP校验和,但函数udp校验和似乎不接受任何参数,我使用jnetpcap 1.4

            Pcap pcap_off = Pcap.openOffline(fileName, errorBuf);  //open pcap

            PcapPacket temp= new PcapPacket(JMemory.Type.POINTER);
            pcap_off.nextEx(temp);
            //System.out.print(temp);
            JBuffer buff=new JBuffer(temp.size());  //new buffer
            Ethernet eth=temp.getHeader(new Ethernet()); 
            Ip4 ip=temp.getHeader(new Ip4());
            Udp udp=temp.getHeader(new Udp());
            Payload data=temp.getHeader(new Payload());

            InetAddress dst = InetAddress.getByName("10.0.0.10");
            InetAddress src = InetAddress.getByName("10.0.0.10");
            ip.destination(dst.getAddress()); //modify ip dst
            ip.checksum(ip.calculateChecksum()); // recalculate ip checksum OK !!!
            eth.transferTo(buff);  
            ip.transferTo(buff, 0, ip.size(), eth.size());                 
         udp.checksum(udp.calculateChecksum());    // NOT OK 
           udp.transferTo(buff, 0, udp.size(), eth.size() + ip.size()); 
           data.transferTo(buff, 0, data.size(), eth.size() + ip.size()+ udp.size());
           JPacket packet =new JMemoryPacket(JProtocol.ETHERNET_ID,buff); //new packet to send

有人可以帮助我获取有关UDP中校验和字段的位置和格式的信息,我可以尝试根据重新计算值手动编写正确的字段。谢谢!!

0 个答案:

没有答案