From a3460915813efd53cd88fffe4f62f53531f9b2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=B6tter?= Date: Tue, 9 May 2017 00:21:21 +0200 Subject: [PATCH] test for UDP packets with checksum 0xFFFF --- .../java/org/pcap4j/packet/UdpPacketTest.java | 22 ++++++++++++++++++ .../UdpPacketTestChecksum0xFFFF.pcap | Bin 0 -> 2837 bytes 2 files changed, 22 insertions(+) create mode 100644 pcap4j-packettest/src/test/resources/UdpPacketTestChecksum0xFFFF.pcap diff --git a/pcap4j-packettest/src/test/java/org/pcap4j/packet/UdpPacketTest.java b/pcap4j-packettest/src/test/java/org/pcap4j/packet/UdpPacketTest.java index 72b48cf8b..50588fa11 100644 --- a/pcap4j-packettest/src/test/java/org/pcap4j/packet/UdpPacketTest.java +++ b/pcap4j-packettest/src/test/java/org/pcap4j/packet/UdpPacketTest.java @@ -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; @@ -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)); + } + } diff --git a/pcap4j-packettest/src/test/resources/UdpPacketTestChecksum0xFFFF.pcap b/pcap4j-packettest/src/test/resources/UdpPacketTestChecksum0xFFFF.pcap new file mode 100644 index 0000000000000000000000000000000000000000..4ff77166b11e3074d3e3c5d3de37ebf5e2124e02 GIT binary patch literal 2837 zcmZuzT})g>6rL@t*|m!;Z4))Mi4RRkeDUsH*`+=SbXl{1{Iqo2K3HQ64@MK~-$RXf z?_63)Sa3s3j6V-lqrUh6bQjvF>26FbO$Du5Q_%;TbhT}wK*0#TyR)8|`@;;=4U+(S z&V1)P-#OpCKYufIdJC#Y&ZkyG$OC`8xTBo;;=!%xWiMjKgPuX5XCHatM0%vvhoZ>) zTr}|%y4&bSr9DSVf53N_cHErzrfaq0>{kP*uCH-u*BeWHH$Gm77uQbwVD2qH)G=ce zH8s?%?29~+pDPX>?oj9_m$!nT+t+PFv>iS80`^_bPdjIc%reT5>2Ttia)^+#| zV;vh6&wz%<>DT5-{bZ@BTCAJKx>3y9_ZEbE+b8qdY-bm}6`@=uuVGEs`0!~VeE&Hb z&WdQT;Cku zJRwvy%cE3%W#Cda>kCrWq<|8i7Ey>4KPAK`Hj!BdGRtP&u#|R2NJ|Q2%)pmYyf`4K z36aeruvx5pC}oNAr_TyxJQt*RQU5L&!wvljx&vhHRK}z%ke?ggZgI#w|48wo{ym$f zY#q3)n`p&NTeW6cl)smCz*!jc;gS?D z%72J)cQ?jw;HuxKz>11{78cddunxE=d)|}cMfDFe?hXn;tH5Q|lsf<&Up^;ej=MK9{w^E=C#QvLz-68JAYlK&o??4|zu(VF1D3CDkb+)e#=eB!gh z*UW!Ck6#OT3t+&(=1?RQih%A;uarpgTg!jDTB-l`Q~!;ghq?^iFbwctL#O7eldZR` z`py%b=q1nf;-}c(ZG!vKOVuFn>PkWhS|dpB1Us$ybPR`N-HxtWS)A686tX6eCV^#> zh6O7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