Class Tcp
Used to manage the TCP state machine. Handle received packets according to current TCP connection Status. Also contains TCB (Transmission Control Block) information.
Inheritance
Inherited Members
Namespace: Cosmos.System.Network.IPv4.TCP
Assembly: Cosmos.System2.dll
Syntax
public class Tcp
Remarks
See RFC 793 for more information.
Constructors
| Improve this Doc View SourceTcp(UInt16, UInt16, Address, Address)
Declaration
public Tcp(ushort localPort, ushort remotePort, Address localIp, Address remoteIp)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | localPort | |
System.UInt16 | remotePort | |
Address | localIp | |
Address | remoteIp |
Fields
| Improve this Doc View SourceDynamicPortStart
Declaration
public static ushort DynamicPortStart
Field Value
Type | Description |
---|---|
System.UInt16 |
LocalEndPoint
The local end-point.
Declaration
public EndPoint LocalEndPoint
Field Value
Type | Description |
---|---|
EndPoint |
RemoteEndPoint
The remote end-point.
Declaration
public EndPoint RemoteEndPoint
Field Value
Type | Description |
---|---|
EndPoint |
Status
The connection status.
Declaration
public Status Status
Field Value
Type | Description |
---|---|
Status |
TcpWindowSize
The TCP window size.
Declaration
public const ushort TcpWindowSize = 8192
Field Value
Type | Description |
---|---|
System.UInt16 |
Methods
| Improve this Doc View SourceGetDynamicPort(Int32)
gets a random port
Declaration
public static ushort GetDynamicPort(int tries = 10)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | tries |
Returns
Type | Description |
---|---|
System.UInt16 |
ProcessCloseWait(TCPPacket)
Process Close_WAIT Status.
Declaration
public void ProcessCloseWait(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | Packet to receive. |
ProcessClosing(TCPPacket)
Process CLOSING Status.
Declaration
public void ProcessClosing(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | Packet to receive. |
ProcessEstablished(TCPPacket)
Processes a ESTABLISHED state TCP packet.
Declaration
public void ProcessEstablished(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | The received packet. |
ProcessFinWait1(TCPPacket)
Process FIN_WAIT1 Status.
Declaration
public void ProcessFinWait1(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | Packet to receive. |
ProcessFinWait2(TCPPacket)
Process FIN_WAIT2 Status.
Declaration
public void ProcessFinWait2(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | Packet to receive. |
ProcessListen(TCPPacket)
Processes a TCP LISTEN state packet and updates the connection status accordingly.
Declaration
public void ProcessListen(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | The incoming TCP packet. |
Remarks
This method handles various types of incoming TCP packets during the LISTEN state and updates the status of the connection accordingly. If an RST packet is received, the packet is passed and no action is taken. If a FIN packet is received, the TCP connection is closed. If an ACK packet is received, the TCP connection is established. If a SYN packet is received, the TCP connection is moved to the SYN_RECEIVED state and an empty packet with the SYN and ACK flags set is sent back.
ProcessSynReceived(TCPPacket)
Processes a TCP SYN_RECEIVED state packet and updates the connection status accordingly.
Declaration
public void ProcessSynReceived(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | The incoming TCP packet. |
Remarks
This method handles an incoming TCP packet during the SYN_RECEIVED state and updates the status of the connection accordingly. If an ACK packet is received with a valid AckNumber, the TCP connection is established. If the AckNumber is invalid, a reset packet is sent back with the AckNumber set to the invalid value.
ProcessSynSent(TCPPacket)
Processes a SYN_SENT state TCP packet and updates the connection state accordingly.
Declaration
public void ProcessSynSent(TCPPacket packet)
Parameters
Type | Name | Description |
---|---|---|
TCPPacket | packet | The TCP packet to process. |
Remarks
If the packet has the SYN flag set, the method sets the initial receive sequence number and responds with an ACK packet if the ACK flag is also set. If the SYN flag is set but not the ACK flag, the method closes the connection and sends an error message. If the packet has only the ACK flag set, the method checks whether the acknowledgment number is within the valid range and updates the send and receive sequence numbers. If the packet has the FIN flag set, the method closes the connection. If the packet has the RST flag set, the method also closes the connection and sends an error message.