Difference between revisions of "Unit UDP"

From Ultibo.org
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
'''Ultibo UDP (User Datagram Protocol) unit'''
 
'''Ultibo UDP (User Datagram Protocol) unit'''
 
''To be documented''
 
  
 
=== Constants ===
 
=== Constants ===
Line 144: Line 142:
  
  
'''UDP protocol transport'''
+
'''UDP specific classes'''
  
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
<code>TUDPProtocolTransport = class(TProtocolTransport)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
| [[TUDPProtocolTransport|<code>TUDPProtocolTransport = class(TProtocolTransport)</code>]]
|-
+
|colspan="2"|&nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
|colspan="2"|&nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
'''UDP protocol'''
+
 
+
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
 
+
<code>TUDPProtocol = class(TNetworkProtocol)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
| <code>constructor Create(AManager:TProtocolManager; const AName:String);</code>
+
| [[TUDPProtocol|<code>TUDPProtocol = class(TNetworkProtocol)</code>]]
| style="width: 50%;"|&nbsp;
+
|-
+
| <code>destructor Destroy; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
|-
+
| <code>FNextPort:Word;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''protected'''</div>
+
|-
+
| <code>function AddTransport(ATransport:TNetworkTransport):Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function RemoveTransport(ATransport:TNetworkTransport):Boolean; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function OpenPort(ASocket:TProtocolSocket; APort:Word):Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function ClosePort(ASocket:TProtocolSocket):Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function FindPort(APort:Word; AWrite,ALock:Boolean):TProtocolPort; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function FindSocket(AFamily,AStruct,AProtocol:Word; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast,AListen,ALock:Boolean; AState:LongWord):TProtocolSocket; override;</code>
+
| &nbsp;
+
|-
+
| <code>procedure FlushSockets(All:Boolean); override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function SelectCheck(ASource,ADest:PFDSet; ACode:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function SendPacket(ASocket:TProtocolSocket; ASource,ADest:Pointer; ASourcePort,ADestPort:Word; APacket:PPacketFragment; ASize,AFlags:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
| <code>function Accept(ASocket:TProtocolSocket; ASockAddr:PSockAddr; AAddrLength:PInteger):TProtocolSocket; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Bind(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function CloseSocket(ASocket:TProtocolSocket):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Connect(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function IoctlSocket(ASocket:TProtocolSocket; ACmd:DWORD; var AArg:u_long):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function GetPeerName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function GetSockName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function GetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Listen(ASocket:TProtocolSocket; ABacklog:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Recv(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function RecvFrom(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AFromAddr:TSockAddr; var AFromLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Select(ANfds:Integer; AReadfds,AWritefds,AExceptfds:PFDSet; ATimeout:PTimeVal):LongInt; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Send(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function SendTo(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AToAddr:TSockAddr; AToLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function SetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Shutdown(ASocket:TProtocolSocket; AHow:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function Socket(AFamily,AStruct,AProtocol:Integer):TProtocolSocket; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function StartProtocol:Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function StopProtocol:Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function ProcessProtocol:Boolean; override;</code>
+
| &nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
'''UDP socket'''
+
 
+
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
 
+
<code>TUDPSocket = class(TProtocolSocket)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
|colspan="2"|Note: SOCK_DGRAM
+
| [[TUDPSocket|<code>TUDPSocket = class(TProtocolSocket)</code>]]
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>constructor Create(AProtocol:TNetworkProtocol; ATransport:TNetworkTransport);</code>
+
| style="width: 50%;"|&nbsp;
+
|-
+
| <code>destructor Destroy; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
|-
+
| <code>FRecvData:TUDPBuffer;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
| <code>property RecvData:TUDPBuffer read FRecvData;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetOption(ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function SetOption(ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer; override;</code>
+
| &nbsp;
+
|-
+
| <code>function IoCtl(ACommand:DWORD; var AArgument:u_long):Integer; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function IsConnected(ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast:Boolean):Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function IsListening(ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast:Boolean):Boolean; override;</code>
+
| &nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
'''UDP state'''
+
 
+
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
 
+
<code>TUDPState = class(TProtocolState)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
| <code>constructor Create;</code>
+
| [[TUDPState|<code>TUDPState = class(TProtocolState)</code>]]
| style="width: 50%;"|&nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
|colspan="2"|&nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
'''UDP buffer'''
+
 
+
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
 
+
<code>TUDPBuffer = class(TSocketBuffer)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
| <code>constructor Create(ASocket:TTransportSocket);</code>
+
| [[TUDPBuffer|<code>TUDPBuffer = class(TSocketBuffer)</code>]]
| style="width: 50%;"|&nbsp;
+
|-
+
| <code>destructor Destroy; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
|-
+
| <code>FOffset:Word;</code>
+
| Offset to RemoteAddress
+
|-
+
| <code>FLength:Word;</code>
+
| Length of RemoteAddress
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>FRead:Pointer;</code>
+
| Pointer to Next Read from Buffer
+
|-
+
| <code>FWrite:Pointer;</code>
+
| Pointer to Next Write to Buffer
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>FCount:LongWord;</code>
+
| Number of Datagrams in Buffer
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>FFirst:PUDPDatagram;</code>
+
| Pointer to First Datagram
+
|-
+
| <code>FLast:PUDPDatagram;</code>
+
| Pointer to Last Datagram
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function AddDatagram(ASize:Integer):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function RemoveDatagram:Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>procedure FlushDatagrams;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''protected'''</div>
+
|-
+
| <code>procedure SetSize(ASize:LongWord); override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
| <code>function GetNext:Integer;</code>
+
| &nbsp;
+
|-
+
| <code>function GetCount:LongWord;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function ReadBuffer(var ABuffer; var ASize:Integer; ARemoteAddress:Pointer; ARemotePort:PWORD; AFlags:Integer):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function WriteBuffer(var ABuffer; ASize:Integer; ARemoteAddress:Pointer; ARemotePort:PWORD):Boolean;</code>
+
| &nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
'''UDP options'''
+
 
+
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
 
+
<code>TUDPOptions = class(TProtocolOptions)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
|colspan="2"|Note: For Get/Set Options Level = IPPROTO_UDP Option = ????
+
| [[TUDPOptions|<code>TUDPOptions = class(TProtocolOptions)</code>]]
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>constructor Create;</code>
+
| style="width: 50%;"|&nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
|-
+
| <code>FOptions:LongWord;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetNoChecksum:Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>procedure SetNoChecksum(ANoChecksum:Boolean);</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
| <code>property NoChecksum:Boolean read GetNoChecksum write SetNoChecksum;</code>
+
| &nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
 
 
<br />
 
<br />
  
Line 495: Line 193:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 510: Line 208:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
! '''Note'''
+
! Note
| If checksum is zero then no checksum was added, return True
+
| If checksum is zero then no checksum was added, return True.
 
|-
 
|-
 
|}
 
|}
Line 525: Line 223:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 537: Line 235:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 549: Line 247:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 561: Line 259:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 573: Line 271:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 585: Line 283:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-

Latest revision as of 05:33, 31 August 2021

Return to Unit Reference


Description


Ultibo UDP (User Datagram Protocol) unit

Constants



UDP specific constants UDP_*
Note: Some UDP definitions are in the Protocol or IP modules
 
UDP_PROTOCOL_NAME = 'UDP';  
 
MIN_UDP_PACKET = 8; Not Counting Adapter and Transport Header
MAX_UDP_PACKET = 8192; Not Counting Adapter and Transport Header
 
UDP_TIMEOUT = 0; Wait forever on a UDP Read
UDP_BUFFER_SIZE = 65536; UDP Receive Buffer Size
 
UDP_MAX_PORT = 65536;  
 
UDP_HEADER_SIZE = 8; SizeOf(TUDPHeader);
 
UDP_DATAGRAM_SIZE = 8; SizeOf(TUDPDatagram)


UDP socket option
See Sockets.pas


UDP port UDP_PORT_*
UDP_PORT_START = 49152; First dynamic port (Previously 1024) As per IANA assignment
UDP_PORT_STOP = 65534; Last dynamic port (Previously 5000) Short of IANA assignment to allow for rollover


Type definitions



UDP header

PUDPHeader = ^TUDPHeader;

TUDPHeader = packed record

Note: Some UDP definitions are in the Protocol or IP modules
Note: 8 Bytes
SourcePort:Word; Network Order
DestPort:Word; Network Order
Length:Word; Network Order
Checksum:Word;  

UDP datagram

PUDPDatagram = ^TUDPDatagram;

TUDPDatagram = record

Note: 8 Bytes (Used by UDPBuffer)
Size:Word; Word to keep size even
RemotePort:Word;  
Next:PUDPDatagram; Followed by RemoteAddress (4 or 16 Bytes)


Class definitions



UDP specific classes

TUDPProtocolTransport = class(TProtocolTransport)
TUDPProtocol = class(TNetworkProtocol)
TUDPSocket = class(TProtocolSocket)
TUDPState = class(TProtocolState)
TUDPBuffer = class(TSocketBuffer)
TUDPOptions = class(TProtocolOptions)


Public variables


None defined

Function declarations



Initialization functions

procedure UDPInit;
Description: To be documented
Note None documented


UDP functions

function CheckUDP(AFamily:Word; ABuffer:Pointer):Boolean;
Description: Verify that the packet is a valid UDP packet
Buffer The complete packet including Transport header
Note If checksum is zero then no checksum was added, return True.


function GetUDPHeaderOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented
Buffer The complete packet including Transport header


function GetUDPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented
Buffer The complete packet including Transport header


function GetUDPDataOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented
Buffer The complete packet including Transport header


function GetUDPDataLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented
Buffer The complete packet including Transport header


function ChecksumUDPRecv(AFamily:Word; APseudo:PIPPseudo; ABuffer:Pointer; AOffset,ALength:Word):Word;
Description: Validate the Checksum of UDP Pseudo, Header and Data on Receive
Note None documented


function ChecksumUDPSend(AFamily:Word; APseudo:PIPPseudo; AHeader:PUDPHeader; AData:Pointer; ALength:Word):Word;
Description: Checksum the UDP Pseudo, Header and Data on Send
Note None documented


Return to Unit Reference