Skip to content

Commit

Permalink
test for UDP packets with checksum 0xFFFF
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoetter committed May 8, 2017
1 parent a449cd7 commit a346091
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.pcap4j.core.PcapHandle;
import org.pcap4j.core.Pcaps;
import org.pcap4j.packet.UdpPacket.UdpHeader;
import org.pcap4j.packet.namednumber.EtherType;
import org.pcap4j.packet.namednumber.IpNumber;
Expand Down Expand Up @@ -170,4 +172,24 @@ public void testHasValidChecksum() {
assertTrue(p.hasValidChecksum(srcAddr, dstAddr, true));
}

@Test
public void testHasValidChecksumFFFF() throws Exception {
PcapHandle pcapHandle = Pcaps.openOffline(resourceDirPath.concat("/UdpPacketTestChecksum0xFFFF.pcap"));
Packet packet = pcapHandle.getNextPacket();
assertNotNull(packet);

assertTrue(packet.contains(IpV4Packet.class));
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
assertNotNull(ipV4Packet);
IpV4Packet.IpV4Header ipV4Header = ipV4Packet.getHeader();
assertNotNull(ipV4Header);

assertTrue(ipV4Packet.contains(UdpPacket.class));
UdpPacket udpPacket = ipV4Packet.get(UdpPacket.class);
assertNotNull(udpPacket);

assertEquals((short)0xFFFF, udpPacket.getHeader().getChecksum());
assertTrue(udpPacket.hasValidChecksum(ipV4Header.getSrcAddr(), ipV4Header.getDstAddr(), false));
}

}
Binary file not shown.

0 comments on commit a346091

Please sign in to comment.