Unit TCP

From Ultibo.org
Jump to: navigation, search

Return to Unit Reference


Description


Ultibo TCP (Transmission Control Protocol) unit

Notes:

Segment handling:

Send adds new segments to the end of the list only accepts ACKs for whole segments.

Recv adds/inserts segments in correct SEQ order accepts overlapping segments only sends ACKs for whole segments.

Send will coalesce small data writes into larger segments if options allow this.

Recv will store the segments exactly as received.


TCP Send and Recv do not use a block buffer as per UDP etc. Instead the data for each Segment is stored in memory (TCP_MAX_MSS) allocated with the Segment. The Free and Used values still track the amount of data in the buffer but this method allows OOB data to be handled correctly.

TCP Sequence numbers are compared using modulo 2^32 arithmetic. The following calculations provide the necessary handling of wraparound etc.

LT = (A - B) < 0

LEQ = (A - B) <= 0

GT = (A - B) > 0

GEQ = (A - B) >= 0


See GlobalSock.pas for actual functions that implement this.

Constants



[Expand]
TCP specific constants TCP_*


[Expand]
TCP socket state TCP_STATE_*


[Expand]
TCP header option TCPOPT_*


[Expand]
TCP header flag TCP_FLAG_*


[Expand]
TCP port TCP_PORT_*


Type definitions



TCP header

[Expand]

PTCPHeader = ^TTCPHeader;

TTCPHeader = packed record

TCP segment

[Expand]

PTCPSegment = ^TTCPSegment;

TTCPSegment = record


Class definitions



TCP specific classes

TTCPProtocolTransport = class(TProtocolTransport)
TTCPProtocol = class(TNetworkProtocol)
TTCPSocket = class(TProtocolSocket)
TTCPState = class(TProtocolState)
TTCPOptions = class(TProtocolOptions)
TTCPSendBuffer = class(TSocketBuffer)
TTCPRecvBuffer = class(TSocketBuffer)


Public variables


None defined

Function declarations



Initialization functions

[Expand]
procedure TCPInit;
Description: To be documented


TCP functions

[Expand]
function CheckTCP(AFamily:Word; ABuffer:Pointer):Boolean;
Description: Verify that the packet is a valid TCP packet


[Expand]
function GetTCPHeaderOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPOptionsLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPDataOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPDataLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function ChecksumTCPRecv(AFamily:Word; APseudo:PIPPseudo; ABuffer:Pointer; AOffset,ALength:Word):Word;
Description: Validate the Checksum of TCP Pseudo, Header and Data on Receive


[Expand]
function ChecksumTCPSend(AFamily:Word; APseudo:PIPPseudo; AHeader:PTCPHeader; AOptions,AData:Pointer; AOptionsLength,ADataLength:Word):Word;
Description: Checksum the TCP Pseudo, Header, Options and Data on Send


Return to Unit Reference