UDP Checksum is calculated wrong (JNetPCAP-1.4.r1425-1)

1 reply [Last post]
TheKahn
Offline
Joined: 05/03/2016

Hi,

I am using JNetPCAP as a traffic generator. I am creating a certain amount of different udp packets and are sending them later onto my firewall. However during the creation of the packets the checksum is either correct or omitted but it should always be correct. I do not know where the error lies. I am posting my method that I use for generating below. The source ip range is from 1.1.1.1 - 9.9.9.9

I use JNETPcap under Linux here is the relevant data:

Distribution: Ubuntu Server 15.04 vivid
uname result: Linux sender 3.19.0-25-generic #26-Ubuntu SMP Fri Jul 24 21:17:31 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
libpcap version: libpcap_1.6.2-2 (got via apt-get libpcap-dev)

public synchronized static JPacket createNormalUDPPacket(int frameLength, byte[] sourceMac, byte[] destinationMac,byte[] sourceAddress, byte[] destinationAddress, int sourcePort, int destinationPort) {

// Header length for UDP is 42
int dataLength = frameLength - 42;
JPacket packet = new JMemoryPacket(frameLength);
packet.order(ByteOrder.BIG_ENDIAN);
packet.setUShort(12, 0x0800);
packet.scan(JProtocol.ETHERNET_ID);
Ethernet ethernet = packet.getHeader(new Ethernet());
ethernet.source(sourceMac);
ethernet.destination(destinationMac);
ethernet.checksum(ethernet.calculateChecksum());


// IP v4 packet
packet.setUByte(14, 0x40 | 0x05);
packet.scan(JProtocol.ETHERNET_ID);
Ip4 ip4 = packet.getHeader(new Ip4());
ip4.type(Ip4.Ip4Type.UDP);
ip4.length(frameLength - ethernet.size());
ip4.source(sourceAddress);
ip4.destination(destinationAddress);
ip4.ttl(32);
ip4.flags(0);
ip4.offset(0);
ip4.checksum(ip4.calculateChecksum());


// UDP packet
packet.scan(JProtocol.ETHERNET_ID);

Udp udp = packet.getHeader(new Udp());
udp.setUShort(0, sourcePort);
udp.setUShort(2, destinationPort);
udp.setUShort(4, frameLength - ethernet.size() - ip4.size());
udp.setUShort(6, udp.calculateChecksum());
packet.setByteArray(42, new byte[dataLength]);
packet.scan(Ethernet.ID);

return packet;
}

I heard that this problem has occured in the past before.

Thank you very much for your help.

leonakatokwa1
Offline
Joined: 05/26/2016
If you ask me JNetPCAP is

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.