Skip to content

Commit

Permalink
kaitoy#300 tcp option support data length larger than 128
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoxingliang committed Sep 5, 2022
1 parent 0b4fad8 commit 7e05ee4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pcap4j-core/src/main/java/org/pcap4j/packet/UnknownTcpOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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(")
Expand Down Expand Up @@ -101,7 +102,7 @@ public TcpOptionKind getKind() {
}

/** @return length */
public byte getLength() {
public short getLength() {
return length;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -178,7 +179,7 @@ public int hashCode() {
public static final class Builder implements LengthBuilder<UnknownTcpOption> {

private TcpOptionKind kind;
private byte length;
private short length;
private byte[] data;
private boolean correctLengthAtBuild;

Expand Down

0 comments on commit 7e05ee4

Please sign in to comment.