我正在尝试在更改 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 中校验和字段的位置和格式的信息,我可以尝试根据重新计算的值手动写入正确的字段。谢谢 !!