Difference between revisions of "Unit UDP"

From Ultibo.org
Jump to: navigation, search
(Created page with "Return to Unit Reference === Description === ---- ''To be documented'' === Constants === ---- ''To be documented'' === Type definitions === ---- ''To...")
 
 
(13 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
''To be documented''
+
'''Ultibo UDP (User Datagram Protocol) unit'''
  
 
=== Constants ===
 
=== Constants ===
 
----
 
----
  
''To be documented''
+
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UDP specific constants''' <code> UDP_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|Note: Some UDP definitions are in the Protocol or IP modules
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>UDP_PROTOCOL_NAME = 'UDP';</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>MIN_UDP_PACKET =  8;</code>
 +
| Not Counting Adapter and Transport Header
 +
|-
 +
| <code>MAX_UDP_PACKET =  8192;</code>
 +
| Not Counting Adapter and Transport Header
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>UDP_TIMEOUT = 0;</code>
 +
| Wait forever on a UDP Read
 +
|-
 +
| <code>UDP_BUFFER_SIZE = 65536;</code>
 +
| UDP Receive Buffer Size
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>UDP_MAX_PORT = 65536;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>UDP_HEADER_SIZE = 8;</code>
 +
| SizeOf(TUDPHeader);
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>UDP_DATAGRAM_SIZE = 8;</code>
 +
| SizeOf(TUDPDatagram)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UDP socket option'''</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|See Sockets.pas
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''UDP port''' <code> UDP_PORT_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>UDP_PORT_START = 49152;</code>
 +
| First dynamic port (Previously 1024) As per IANA assignment
 +
|-
 +
| <code>UDP_PORT_STOP = 65534;</code>
 +
| Last dynamic port (Previously 5000) Short of IANA assignment to allow for rollover
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Type definitions ===
 
=== Type definitions ===
 
----
 
----
  
''To be documented''
+
 
 +
'''UDP header'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PUDPHeader = ^TUDPHeader;</code>
 +
 
 +
<code>TUDPHeader = packed record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|Note: Some UDP definitions are in the Protocol or IP modules
 +
|-
 +
|colspan="2"|Note: 8 Bytes
 +
|-
 +
| <code>SourcePort:Word;</code>
 +
| Network Order
 +
|-
 +
| <code>DestPort:Word;</code>
 +
| Network Order
 +
|-
 +
| <code>Length:Word;</code>
 +
| Network Order
 +
|-
 +
| <code>Checksum:Word;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div> 
 +
 
 +
'''UDP datagram''' 
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PUDPDatagram = ^TUDPDatagram;</code>
 +
 
 +
<code>TUDPDatagram = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|Note: 8 Bytes (Used by UDPBuffer)
 +
|-
 +
| <code>Size:Word;</code>
 +
| Word to keep size even
 +
|-
 +
| <code>RemotePort:Word;</code>
 +
| &nbsp;
 +
|-
 +
| <code>Next:PUDPDatagram;</code>
 +
| Followed by RemoteAddress (4 or 16 Bytes)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 
 +
=== Class definitions ===
 +
----
 +
 
 +
 
 +
'''UDP specific classes'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TUDPProtocolTransport|<code>TUDPProtocolTransport = class(TProtocolTransport)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TUDPProtocol|<code>TUDPProtocol = class(TNetworkProtocol)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TUDPSocket|<code>TUDPSocket = class(TProtocolSocket)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TUDPState|<code>TUDPState = class(TProtocolState)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TUDPBuffer|<code>TUDPBuffer = class(TSocketBuffer)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TUDPOptions|<code>TUDPOptions = class(TProtocolOptions)</code>]]
 +
|-
 +
|}
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
 
----
 
----
  
''To be documented''
+
''None defined''
  
 
=== Function declarations ===
 
=== Function declarations ===
 
----
 
----
  
''To be documented''
 
  
 +
'''Initialization functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure UDPInit;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''UDP functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function CheckUDP(AFamily:Word; ABuffer:Pointer):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Verify that the packet is a valid UDP packet</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Buffer
 +
| The complete packet including Transport header
 +
|-
 +
! Note
 +
| If checksum is zero then no checksum was added, return True.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function GetUDPHeaderOffset(AFamily:Word; ABuffer:Pointer):Word;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Buffer
 +
| The complete packet including Transport header
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function GetUDPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Buffer
 +
| The complete packet including Transport header
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function GetUDPDataOffset(AFamily:Word; ABuffer:Pointer):Word;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Buffer
 +
| The complete packet including Transport header
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function GetUDPDataLength(AFamily:Word; ABuffer:Pointer):Word;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Buffer
 +
| The complete packet including Transport header
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function ChecksumUDPRecv(AFamily:Word; APseudo:PIPPseudo; ABuffer:Pointer; AOffset,ALength:Word):Word;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Validate the Checksum of UDP Pseudo, Header and Data on Receive</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function ChecksumUDPSend(AFamily:Word; APseudo:PIPPseudo; AHeader:PUDPHeader; AData:Pointer; ALength:Word):Word;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Checksum the UDP Pseudo, Header and Data on Send</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
Return to [[Unit_Reference|Unit Reference]]
 
Return to [[Unit_Reference|Unit Reference]]

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