Unit IGMP

From Ultibo.org
Revision as of 03:30, 13 April 2017 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


Ultibo IGMP (Internet Group Management Protocol) unit

To be documented

Constants



IGMP protocol IGMP_PROTOCOL_*
Note: Some IGMP definitions are in the Protocol or IP modules
 
IGMP_PROTOCOL_NAME = 'IGMP';  


IGMP specific constants IGMP_*
IGMP_TIMEOUT = 0; Wait forever on a IGMP Read
IGMP_BUFFER_SIZE = 65536; IGMP Receive Buffer Size
 
IGMP_HEADER_SIZE = 8; SizeOf(TIGMPHeader);
 
IGMP_PACKET_SIZE = 8; SizeOf(TIGMPPacket)
 
IGMP_QUERY_TIMEOUT = 5000;  
IGMP_REPORT_TIMEOUT = 5000;  
 
IGMP_TRANSMIT_COUNT = 3;  


Type definitions



IGMP header

PIGMPHeader = ^TIGMPHeader;

TIGMPHeader = packed record

Note: Some IGMP definitions are in the Protocol or IP modules
IGMPType:Byte; type of IGMP message
RespTime:Byte; Query only otherwise 0 (Always zero in Version 1 (Assume 100))
Checksum:Word; 1s Compliment IP-style checksum
Address:TInAddr; group address being reported or queried (zero for "General" queries)

IGMP packet

PIGMPPacket = ^TIGMPPacket;

TIGMPPacket = record

Note: 8 Bytes (Used by IGMPBuffer)
Size:LongWord; LongWord to keep size even
Next:PIGMPPacket; Followed by RemoteAddress (4 or 16 Bytes)


Class definitions



IGMP protocol transport

TIGMPProtocolTransport = class(TProtocolTransport)

constructor Create;  
destructor Destroy; override;  
public
Socket:TIGMPSocket; Socket for sending replies

IGMP protocol

TIGMPProtocol = class(TNetworkProtocol)

constructor Create(AManager:TProtocolManager; const AName:String);  
destructor Destroy; override;  
private
FGroups:TNetworkList; List of TIGMPGroup objects
 
function PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;  
function ControlHandler(AHandle:THandle; ASource,ADest:Pointer; AProtocol,ACommand,ACode:Word; AAddress,AData:Pointer; ASize:Integer):Boolean;  
 
function SendIGMP1Report(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;  
function SendIGMP2Report(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;  
function SendIGMP2Leave(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;  
function SendIGMP1Query(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;  
function SendIGMP2Query(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;  
 
function GetGroup(ATransport:TIGMPProtocolTransport; const AAddress:TInAddr; ALock:Boolean):TIGMPGroup;  
function GetGroupByNext(APrevious:TIGMPGroup; ALock,AUnlock:Boolean):TIGMPGroup;  
function AddGroup(ATransport:TIGMPProtocolTransport; const AAddress:TInAddr; const AHardware:THardwareAddress; ALock:Boolean):TIGMPGroup;  
function RemoveGroup(ATransport:TIGMPProtocolTransport; const AAddress:TInAddr):Boolean;  
procedure FlushGroups(All:Boolean);  
function ProcessGroups:Boolean;  
protected
function AddTransport(ATransport:TNetworkTransport):Boolean; override;  
function RemoveTransport(ATransport:TNetworkTransport):Boolean; override;  
 
function FindSocket(AFamily,AStruct,AProtocol:Word; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast,AListen,ALock:Boolean; AState:LongWord):TProtocolSocket; override;  
procedure FlushSockets(All:Boolean); override;  
 
function SelectCheck(ASource,ADest:PFDSet; ACode:Integer):Integer; override;  
 
function SendPacket(ASocket:TProtocolSocket; ASource,ADest:Pointer; ASourcePort,ADestPort:Word; APacket:PPacketFragment; ASize,AFlags:Integer):Integer; override;  
public
function Accept(ASocket:TProtocolSocket; ASockAddr:PSockAddr; AAddrLength:PInteger):TProtocolSocket; override;  
function Bind(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer; override;  
function CloseSocket(ASocket:TProtocolSocket):Integer; override;  
function Connect(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer; override;  
function IoctlSocket(ASocket:TProtocolSocket; ACmd:DWORD; var AArg:u_long):Integer; override;  
function GetPeerName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer; override;  
function GetSockName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer; override;  
function GetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer; override;  
function Listen(ASocket:TProtocolSocket; ABacklog:Integer):Integer; override;  
function Recv(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer; override;  
function RecvFrom(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AFromAddr:TSockAddr; var AFromLength:Integer):Integer; override;  
function Select(ANfds:Integer; AReadfds,AWritefds,AExceptfds:PFDSet; ATimeout:PTimeVal):LongInt; override;  
function Send(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer; override;  
function SendTo(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AToAddr:TSockAddr; AToLength:Integer):Integer; override;  
function SetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer; override;  
function Shutdown(ASocket:TProtocolSocket; AHow:Integer):Integer; override;  
function Socket(AFamily,AStruct,AProtocol:Integer):TProtocolSocket; override;  
 
function StartProtocol:Boolean; override;  
function StopProtocol:Boolean; override;  
function ProcessProtocol:Boolean; override;  

IGMP group

TIGMPGroup = class(TListObject)

constructor Create;  
destructor Destroy; override;  
private
FLock:TCriticalSectionHandle;  
 
FCount:Word; Number of memberships
FQueryTime:Int64; IGMP query reply timer
FReportTime:Int64; IGMP report reply/transmit timer
FTransmitCount:Word; IGMP report transmit counter
FAddress:TInAddr; IP address of group
FHardware:THardwareAddress; Hardware address of group
FTransport:TNetworkTransport; Transport provider for group
 
procedure SetCount(ACount:Word);  
function GetActive:Boolean;  
procedure SetQueryTime(const AQueryTime:Int64);  
procedure SetReportTime(const AReportTime:Int64);  
procedure SetTransmitCount(ATransmitCount:Word);  
procedure SetAddress(const AAddress:TInAddr);  
procedure SetHardware(const AHardware:THardwareAddress);  
procedure SetTransport(ATransport:TNetworkTransport);  
public
property Count:Word read FCount write SetCount;  
property Active:Boolean read GetActive;  
property QueryTime:Int64 read FQueryTime write SetQueryTime;  
property ReportTime:Int64 read FReportTime write SetReportTime;  
property TransmitCount:Word read FTransmitCount write SetTransmitCount;  
property Address:TInAddr read FAddress write SetAddress;  
property Hardware:THardwareAddress read FHardware write SetHardware;  
property Transport:TNetworkTransport read FTransport write SetTransport;  
 
function AcquireLock:Boolean;  
function ReleaseLock:Boolean;  
 
procedure IncrementCount;  
procedure DecrementCount;  
procedure IncrementTransmitCount;  
procedure DecrementTransmitCount;  

IGMP socket

TIGMPSocket = class(TProtocolSocket)

Note: SOCK_RAW
 
constructor Create(AProtocol:TNetworkProtocol; ATransport:TNetworkTransport);  
destructor Destroy; override;  
private
FRecvData:TIGMPBuffer;  
public
property RecvData:TIGMPBuffer read FRecvData;  
 
function IoCtl(ACommand:DWORD; var AArgument:u_long):Integer; override;  
 
function IsConnected(ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast:Boolean):Boolean; override;  
function IsListening(ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast:Boolean):Boolean; override;  

IGMP buffer

TIGMPBuffer = class(TSocketBuffer)

constructor Create(ASocket:TTransportSocket);  
destructor Destroy; override;  
private
FOffset:Word; Offset to RemoteAddress
FLength:Word; Length of RemoteAddress
 
FRead:Pointer; Pointer to Next Read from Buffer
FWrite:Pointer; Pointer to Next Write to Buffer
 
FCount:LongWord; Number of Packets in Buffer
 
FFirst:PIGMPPacket; Pointer to First Packet
FLast:PIGMPPacket; Pointer to Last Packet
 
function AddPacket(ASize:Integer):Boolean;  
function RemovePacket:Boolean;  
procedure FlushPackets;  
protected
procedure SetSize(ASize:LongWord); override;  
public
function GetNext:Integer;  
function GetCount:LongWord;  
 
function ReadBuffer(var ABuffer; var ASize:Integer; ARemoteAddress:Pointer; AFlags:Integer):Boolean;  
function WriteBuffer(var ABuffer; ASize:Integer; ARemoteAddress:Pointer):Boolean;  


Public variables


None defined

Function declarations



Initialization functions

procedure IGMPInit;
Description: To be documented
Note None documented


IGMP functions

function CheckIGMP(AFamily:Word; ABuffer:Pointer):Boolean;
Description: Verify that the packet is a valid IGMP packet
Buffer The complete packet including Transport header


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


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


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


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


function ChecksumIGMP(AFamily:Word; ABuffer:Pointer; AOffset,ALength:Word):Word;
Description: Checksum the IGMP Header on Send/Validate the Checksum on Receive
Note Checksum is calculated on the whole packet (Header and Data)


Return to Unit Reference