From 7e05ee42113b1e8def590267509274bfe8df2a73 Mon Sep 17 00:00:00 2001 From: "gaoxingliang@outlook.com" Date: Mon, 5 Sep 2022 20:34:32 +0800 Subject: [PATCH 1/3] #300 tcp option support data length larger than 128 --- .../org/pcap4j/packet/UnknownTcpOption.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java b/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java index e6b1f0ae8..f8676b541 100644 --- a/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java +++ b/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java @@ -7,10 +7,11 @@ package org.pcap4j.packet; -import java.util.Arrays; -import org.pcap4j.packet.TcpPacket.TcpOption; -import org.pcap4j.packet.namednumber.TcpOptionKind; -import org.pcap4j.util.ByteArrays; +import org.pcap4j.packet.TcpPacket.*; +import org.pcap4j.packet.namednumber.*; +import org.pcap4j.util.*; + +import java.util.*; /** * @author Kaito Yamada @@ -22,7 +23,7 @@ public final class UnknownTcpOption implements TcpOption { private static final long serialVersionUID = -893085251311518110L; private final TcpOptionKind kind; - private final byte length; + private final short length; private final byte[] data; /** @@ -54,7 +55,7 @@ private UnknownTcpOption(byte[] rawData, int offset, int length) throws IllegalR } this.kind = TcpOptionKind.getInstance(rawData[offset]); - this.length = rawData[1 + offset]; + this.length = (short) (rawData[1 + offset] & 0xff); if (length < this.length) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data is too short to build this option(") @@ -101,7 +102,7 @@ public TcpOptionKind getKind() { } /** @return length */ - public byte getLength() { + public short getLength() { return length; } @@ -121,7 +122,7 @@ public byte[] getData() { public byte[] getRawData() { byte[] rawData = new byte[length()]; rawData[0] = kind.value(); - rawData[1] = length; + rawData[1] = (byte) length; System.arraycopy(data, 0, rawData, 2, data.length); return rawData; } @@ -178,7 +179,7 @@ public int hashCode() { public static final class Builder implements LengthBuilder { private TcpOptionKind kind; - private byte length; + private short length; private byte[] data; private boolean correctLengthAtBuild; From 8247242e2c0b028bfaa6f6d82c45883a1b0a26ad Mon Sep 17 00:00:00 2001 From: "gaoxingliang@outlook.com" Date: Mon, 5 Sep 2022 20:39:45 +0800 Subject: [PATCH 2/3] #300 tcp option support data length larger than 128 --- .../main/java/org/pcap4j/packet/UnknownTcpOption.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java b/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java index f8676b541..d3ded279b 100644 --- a/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java +++ b/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java @@ -7,11 +7,10 @@ package org.pcap4j.packet; -import org.pcap4j.packet.TcpPacket.*; -import org.pcap4j.packet.namednumber.*; -import org.pcap4j.util.*; - -import java.util.*; +import java.util.Arrays; +import org.pcap4j.packet.TcpPacket.TcpOption; +import org.pcap4j.packet.namednumber.TcpOptionKind; +import org.pcap4j.util.ByteArrays; /** * @author Kaito Yamada From 602b6256fb630f798d1ec19d7ed3fe345fbe1691 Mon Sep 17 00:00:00 2001 From: "gaoxingliang@outlook.com" Date: Mon, 5 Sep 2022 20:46:20 +0800 Subject: [PATCH 3/3] #300 tcp option support data length larger than 128 --- .../java/org/pcap4j/packet/UnknownTcpOption.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java b/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java index d3ded279b..a25142d8a 100644 --- a/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java +++ b/pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java @@ -22,7 +22,7 @@ public final class UnknownTcpOption implements TcpOption { private static final long serialVersionUID = -893085251311518110L; private final TcpOptionKind kind; - private final short length; + private final byte length; private final byte[] data; /** @@ -54,8 +54,8 @@ private UnknownTcpOption(byte[] rawData, int offset, int length) throws IllegalR } this.kind = TcpOptionKind.getInstance(rawData[offset]); - this.length = (short) (rawData[1 + offset] & 0xff); - if (length < this.length) { + this.length = rawData[1 + offset]; + if (length < getLengthAsInt()) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data is too short to build this option(") .append(this.length) @@ -68,7 +68,7 @@ private UnknownTcpOption(byte[] rawData, int offset, int length) throws IllegalR throw new IllegalRawDataException(sb.toString()); } - if (this.length > 2) this.data = ByteArrays.getSubArray(rawData, 2 + offset, this.length - 2); + if (this.length > 2) this.data = ByteArrays.getSubArray(rawData, 2 + offset, getLengthAsInt() - 2); else this.data = new byte[] {}; } @@ -101,7 +101,7 @@ public TcpOptionKind getKind() { } /** @return length */ - public short getLength() { + public byte getLength() { return length; } @@ -121,7 +121,7 @@ public byte[] getData() { public byte[] getRawData() { byte[] rawData = new byte[length()]; rawData[0] = kind.value(); - rawData[1] = (byte) length; + rawData[1] = length; System.arraycopy(data, 0, rawData, 2, data.length); return rawData; } @@ -178,7 +178,7 @@ public int hashCode() { public static final class Builder implements LengthBuilder { private TcpOptionKind kind; - private short length; + private byte length; private byte[] data; private boolean correctLengthAtBuild;