|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jnetpcap.nio.JMemory
org.jnetpcap.nio.JBuffer
org.jnetpcap.packet.JHeader
org.jnetpcap.packet.JHeaderMap<Tcp>
org.jnetpcap.protocol.tcpip.Tcp
@Header public class Tcp
Transmission Control Protocol (TCP).
The Transmission Control Protocol (TCP) is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol (IP) and therefore the entire suite is commonly referred to as TCP/IP. TCP provides the service of exchanging data reliably directly between two network hosts, whereas IP handles addressing and routing message across one or more networks. In particular, TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. TCP is the protocol that major Internet applications rely on, such as the World Wide Web, e-mail, and file transfer. Other applications, which do not require reliable data stream service, may use the User Datagram Protocol (UDP) which provides a datagram service, which emphasizes reduced latency over reliability.
A TCP segment consists of a segment header and a data section. The TCP header contains 10 mandatory fields, and an optional extension field (Options).
The data section follows the header. Its contents are the payload data carried for the application. The length of the data section is not specified in the TCP segment header. It can be calculated by subtracting the combined length of the TCP header and the encapsulating IP segment header from the total IP segment length (specified in the IP segment header).
The header structure is as follows:
| Nested Class Summary | |
|---|---|
static class |
Tcp.AlternateChecksum
The option described in this memo provides a mechanism to negotiate the use of an alternate checksum at connection-establishment time, as well as a mechanism to carry additional checksum information for algorithms that utilize checksums that are longer than 16 bits. |
static class |
Tcp.AlternateChecksumRequest
The option described in this memo provides a mechanism to negotiate the use of an alternate checksum at connection-establishment time, as well as a mechanism to carry additional checksum information for algorithms that utilize checksums that are longer than 16 bits. |
static class |
Tcp.Flag
Flags (8 bits) (aka Control bits) - contains 8 1-bit flags CWR (1 bit) - Congestion Window Reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168). |
static class |
Tcp.MSS
The TCP Maximum Segment Size option can be used to specify the maximum segment size that the receiver should use. |
static class |
Tcp.NoOp
No operation. |
static class |
Tcp.SACK
TCP may experience poor performance when multiple packets are lost from one window of data. |
static class |
Tcp.SACK_PERMITTED
The TCP SACK permitted option may be sent in a SYN by a TCP that has been extended to receive the SACK option once the connection has opened. |
static class |
Tcp.TcpOption
Options (Variable 0-320 bits, divisible by 32) - The length of this field is determined by the data offset field. |
static class |
Tcp.Timestamp
TCP timestamps, defined in RFC 1323, help TCP compute the round-trip time between the sender and receiver. |
static class |
Tcp.WindowScale
The window scale extension expands the definition of the TCP window to 32 bits and then uses a scale factor to carry this 32 bit value in the 16 bit Window field of the TCP header (SEG.WND in RFC-793). |
| Nested classes/interfaces inherited from class org.jnetpcap.packet.JHeader |
|---|
JHeader.State |
| Nested classes/interfaces inherited from class org.jnetpcap.nio.JMemory |
|---|
JMemory.Type |
| Field Summary | |
|---|---|
static int |
ID
Unique numerical ID for this protocol header definition. |
| Fields inherited from class org.jnetpcap.packet.JHeaderMap |
|---|
MAX_HEADERS, optionsBitmap, optionsLength, optionsOffsets, X_HEADERS |
| Fields inherited from class org.jnetpcap.packet.JHeader |
|---|
annotatedHeader, BYTE, EMPTY_HEADER_ARRAY, isSubHeader, packet, state |
| Fields inherited from class org.jnetpcap.nio.JMemory |
|---|
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER |
| Constructor Summary | |
|---|---|
Tcp()
|
|
| Method Summary | |
|---|---|
long |
ack()
Acknowledgment number (32 bits). |
void |
ack(long ack)
Ack. |
int |
calculateChecksum()
Calculates a checksum using protocol specification for a header. |
int |
checksum()
Checksum (16 bits). |
void |
checksum(int crc)
Checksum. |
java.lang.String |
checksumDescription()
Returns a dynamic description of the checksum field. |
protected void |
decodeHeader()
Decode header. |
int |
destination()
Destination port (16 bits). |
void |
destination(int value)
Sets a new value for the destination field. |
boolean |
flags_ACK()
ACK (1 bit) - indicates that the Acknowledgment field is significant. |
void |
flags_ACK(boolean value)
Sets new value for the bit flag. |
boolean |
flags_CWR()
CWR (1 bit) - Congestion Window Reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168). |
void |
flags_CWR(boolean value)
Sets new value for the bit flag. |
boolean |
flags_ECE()
ECE (1 bit) - ECN-Echo indicates If the SYN flag is set, that the TCP peer is ECN capable. |
void |
flags_ECE(boolean value)
Sets new value for the bit flag. |
boolean |
flags_FIN()
FIN (1 bit) - No more data from sender. |
void |
flags_FIN(boolean value)
Sets new value for the bit flag. |
boolean |
flags_PSH()
PSH (1 bit) - Push function. |
void |
flags_PSH(boolean value)
Sets new value for the bit flag. |
boolean |
flags_RST()
RST (1 bit) - Reset the connection. |
void |
flags_RST(boolean value)
Sets new value for the bit flag. |
boolean |
flags_SYN()
SYN (1 bit) - Synchronize sequence numbers. |
void |
flags_SYN(boolean value)
Sets new value for the bit flag. |
boolean |
flags_URG()
URG (1 bit) - indicates that the Urgent pointer field is significant. |
void |
flags_URG(boolean value)
Sets new value for the bit flag. |
int |
flags()
Flags (8 bits) (aka Control bits) - contains 8 1-bit flags CWR (1 bit) - Congestion Window Reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168). |
void |
flags(int value)
Sets a new value for the flags field (8-bits). |
java.lang.String |
flagsCompactString()
Returns a compact string representation of the flags contained within flags field. |
java.util.Set<Tcp.Flag> |
flagsEnum()
Retruns a collection set representation of the flags contained within the flags field. |
int |
hashCode()
Returns a bi-directional hashcode for this header. |
static int |
headerLength(JBuffer buffer,
int offset)
Calculates the length of a tcp header. |
int |
hlen()
Data offset (4 bits). |
void |
hlen(int length)
Hlen. |
boolean |
isChecksumValid()
Checks if the checksum is valid, for un-fragmented packets. |
int |
reserved()
Reserved (4 bits). |
void |
reserved(int value)
Sets a new value for the field. |
long |
seq()
Sequence number (32 bits). |
void |
seq(long seq)
Seq. |
int |
source()
Source port (16 bits). |
void |
source(int src)
Sets a new value for the field (16 bits). |
int |
uniHashCode()
Uni-directional hashcode. |
int |
urgent()
Urgent pointer (16 bits). |
void |
urgent(int urg)
Urgent. |
int |
window()
Window (16 bits). |
void |
window(int value)
Sets the window field to new value. |
int |
windowScaled()
A scaled, window field value. |
| Methods inherited from class org.jnetpcap.packet.JHeaderMap |
|---|
getSubHeader, getSubHeaders, hasSubHeader, hasSubHeader, hasSubHeaders, setSubHeader, setSubHeaders |
| Methods inherited from class org.jnetpcap.nio.JBuffer |
|---|
findUTF8String, getByte, getByteArray, getByteArray, getByteArray, getDouble, getFloat, getInt, getLong, getShort, getUByte, getUInt, getUShort, getUTF8Char, getUTF8String, getUTF8String, getUTF8String, getUTF8String, isReadonly, order, order, peer, peer, peer, peer, setByte, setByteArray, setByteBuffer, setDouble, setFloat, setInt, setLong, setShort, setShort0, setUByte, setUInt, setUShort, transferFrom, transferFrom, transferFrom, transferTo, transferTo, transferTo |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int ID
| Constructor Detail |
|---|
public Tcp()
| Method Detail |
|---|
@HeaderLength
public static int headerLength(JBuffer buffer,
int offset)
buffer - buffer containing packet and/or tcp header dataoffset - offset into the buffer where tcp header start (in bytes)
@Field(offset=64,
length=16,
format="%x")
public long ack()
public void ack(long ack)
ack - the ackpublic int calculateChecksum()
calculateChecksum in interface JHeaderChecksum
@Field(offset=128,
length=16,
format="%x")
public int checksum()
checksum in interface JHeaderChecksumpublic void checksum(int crc)
crc - the crc@Dynamic(value=DESCRIPTION) public java.lang.String checksumDescription()
protected void decodeHeader()
decodeHeader in class JHeaderJHeader.decodeHeader()
@Field(offset=16,
length=16)
@FlowKey(index=2,
reversable=true)
public int destination()
public void destination(int value)
value - new value for the field
@Field(offset=104,
length=8,
format="%x")
public int flags()
public void flags(int value)
value - new value for the field
@Field(parent="flags",
offset=4,
length=1,
format="%b",
display="ack",
description="acknowledgment")
public boolean flags_ACK()
public void flags_ACK(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=7,
length=1,
format="%b",
display="cwr",
description="reduced (cwr)")
public boolean flags_CWR()
public void flags_CWR(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=6,
length=1,
format="%b",
display="ece",
description="ECN echo flag")
public boolean flags_ECE()
public void flags_ECE(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=0,
length=1,
format="%b",
display="fin",
description="closing down connection")
public boolean flags_FIN()
public void flags_FIN(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=3,
length=1,
format="%b",
display="ack",
description="push current segment of data")
public boolean flags_PSH()
public void flags_PSH(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=2,
length=1,
format="%b",
display="ack",
description="reset connection")
public boolean flags_RST()
public void flags_RST(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=1,
length=1,
format="%b",
display="ack",
description="synchronize connection, startup")
public boolean flags_SYN()
public void flags_SYN(boolean value)
value - sets the flag bit, false clears it
@Field(parent="flags",
offset=5,
length=1,
format="%b",
display="ack",
description="urgent, out-of-band data")
public boolean flags_URG()
public void flags_URG(boolean value)
value - sets the flag bit, false clears itpublic java.lang.String flagsCompactString()
public java.util.Set<Tcp.Flag> flagsEnum()
public int hashCode()
hashCode in class java.lang.ObjectuniHashCode()
@Field(offset=96,
length=4)
public int hlen()
public void hlen(int length)
length - in 4 byte wordspublic boolean isChecksumValid()
isChecksumValid in interface JHeaderChecksum
@Field(offset=100,
length=4)
public int reserved()
public void reserved(int value)
value - new value (4 bits)
@Field(offset=32,
length=16,
format="%x")
public long seq()
public void seq(long seq)
seq - the seq
@Field(offset=0,
length=16)
@FlowKey(index=2,
reversable=true)
public int source()
public void source(int src)
src - new value (16 bits)public int uniHashCode()
@Field(offset=144,
length=16)
public int urgent()
public void urgent(int urg)
urg - the urg
@Field(offset=112,
length=16)
public int window()
TCP uses a sliding window flow control protocol. In each TCP segment, the receiver specifies in the receive window field the amount of additional received data (in bytes) that it is willing to buffer for the connection. The sending host can send only up to that amount of data before it must wait for an acknowledgment and window update from the receiving host.
When a receiver advertises a window size of 0, the sender stops sending data and starts the persist timer. The persist timer is used to protect TCP from a deadlock situation that could arise if the window size update from the receiver is lost and the sender has no more data to send while the receiver is waiting for the new window size update. When the persist timer expires, the TCP sender sends a small packet so that the receiver sends an acknowledgement with the new window size.
If a receiver is processing incoming data in small increments, it may repeatedly advertise a small receive window. This is referred to as the silly window syndrome, since it is inefficient to send only a few bytes of data in a TCP segment, given the relatively large overhead of the TCP header. TCP senders and receivers typically employ flow control logic to specifically avoid repeatedly sending small segments. The sender-side silly window syndrome avoidance logic is referred to as Nagle's algorithm.
Since the size field cannot be expanded, a scaling factor is used. The TCP window scale option, as defined in RFC 1323, is an option used to increase the maximum window size from 65,535 bytes to 1 Gigabyte. Scaling up to larger window sizes is a part of what is necessary for TCP Tuning.
The window scale option is used only during the TCP 3-way handshake. The window scale value represents the number of bits to left-shift the 16-bit window size field. The window scale value can be set from 0 (no shift) to 14 for each direction independently. Both sides must send the option in their SYN segments to enable window scaling in either direction.
Some routers and packet firewalls rewrite the window scaling factor during a transmission. This causes sending and receiving sides to assume different TCP window sizes. The result is non-stable traffic that may be very slow. The problem is visible on some sending and receiving sites behind the path of defective routers.
public void window(int value)
value - new value for the fieldpublic int windowScaled()
This getter method, takes into account window scaling, as described below, and applies the scaling factor and returning the value.
Since the size field cannot be expanded, a scaling factor is used. The TCP window scale option, as defined in RFC 1323, is an option used to increase the maximum window size from 65,535 bytes to 1 Gigabyte. Scaling up to larger window sizes is a part of what is necessary for TCP Tuning.
The window scale option is used only during the TCP 3-way handshake. The window scale value represents the number of bits to left-shift the 16-bit window size field. The window scale value can be set from 0 (no shift) to 14 for each direction independently. Both sides must send the option in their SYN segments to enable window scaling in either direction.
Some routers and packet firewalls rewrite the window scaling factor during a transmission. This causes sending and receiving sides to assume different TCP window sizes. The result is non-stable traffic that may be very slow. The problem is visible on some sending and receiving sites behind the path of defective routers.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||