0

i'm trying to recalculate UDP Checksum on a packet where i changed IPD destination, but the function udp checksum seems to doesn't accept any parameter,i'm using 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

Some one can help me to get information about the location and format of the checksum field in UDP, i can try to write manually the proper field in according to the recalculate value. Thanks !!

  • There at least three different JPcap implementations. You don't specify which one you're using, which is issue A, but if its `checksum()` method doesn't accept parameters, i.e. is a getter not a setter, it's hard to see what anyone can do about it. – user207421 Jan 10 '15 at 09:44
  • Thanks for answer, i read on "jnetpcap-src-1.3.0-1" documentation that checksum() is a setter method, but i 'm using 1.4.b0004 version – franktiello Jan 10 '15 at 10:12
  • i solved in this way : int cs = udp.calculateChecksum(); udp.setUShort(6, cs); – franktiello Jan 10 '15 at 13:44

0 Answers0