TIGMPProtocol

From Ultibo.org
Jump to: navigation, search

Return to Unit IGMP


Description


To be documented

Class definitions



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 SelectCheck(ASource,ADest:PFDSet; ACode:Integer):Integer; override;  
function SelectWait(ASocket:TProtocolSocket;ACode:Integer;ATimeout:LongWord):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 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 StartProtocol:Boolean; override;  
function StopProtocol:Boolean; override;  
function ProcessProtocol:Boolean; override;  


Function declarations



constructor TIGMPProtocol.Create(AManager:TProtocolManager; const AName:String);
Description: To be documented
Note None documented


destructor TIGMPProtocol.Destroy;
Description: To be documented
Note None documented


function TIGMPProtocol.PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
Description: Process a packet received by a Transport
Handle The Handle of the Protocol Transport the packet was received from
Source The source address of the received packet (Set by Transport)
Dest The destination address of the received packet (Set by Transport)
Packet The received packet (The complete packet including Transport header)
Size The size of the received packet in bytes
Broadcast True if the destination address is a broadcast address


function TIGMPProtocol.ControlHandler(AHandle:THandle; ASource,ADest:Pointer; AProtocol,ACommand,ACode:Word; AAddress,AData:Pointer; ASize:Integer):Boolean;
Description: Process a network control request from a Transport
Handle The Handle of the Protocol Transport the control request is from
Source The source address of the control request (Set by Transport)
Dest The destination address of the control request (Set by Transport)
Protocol The control protocol requested
Command The control command to send
Code The control code to send
Address The control address to send
Data The control data to send
Size The size of the control data in bytes
Note Addresses are passed in Host order


function TIGMPProtocol.SendIGMP1Report(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;
Description: Send an IGMP V1 report message (Join Group)
Socket The socket to use for sending the message
Source The source address to use for the message
Dest The destination address to use for the message
Address The address to send for the message
Note Addresses are passed in Host order

Caller must hold the Socket lock


function TIGMPProtocol.SendIGMP2Report(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;
Description: Send an IGMP V2 report message (Join Group)
Socket The socket to use for sending the message
Source The source address to use for the message
Dest The destination address to use for the message
Address The address to send for the message
Note Addresses are passed in Host order

Caller must hold the Socket lock


function TIGMPProtocol.SendIGMP2Leave(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;
Description: Send an IGMP leave message (Leave Group)
Socket The socket to use for sending the message
Source The source address to use for the message
Dest The destination address to use for the message
Address The address to send for the message
Note Addresses are passed in Host order

Caller must hold the Socket lock


function TIGMPProtocol.SendIGMP1Query(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;
Description: Send an IGMP V1 query message
Socket The socket to use for sending the message
Source The source address to use for the message
Dest The destination address to use for the message
Address The address to send for the message
Note Addresses are passed in Host order

Caller must hold the Socket lock


function TIGMPProtocol.SendIGMP2Query(ASocket:TIGMPSocket; ASource,ADest,AAddress:Pointer):Boolean;
Description: Send an IGMP V2 query message
Socket The socket to use for sending the message
Source The source address to use for the message
Dest The destination address to use for the message
Address The address to send for the message
Note Addresses are passed in Host order

Caller must hold the Socket lock


function TIGMPProtocol.GetGroup(ATransport:TIGMPProtocolTransport; const AAddress:TInAddr; ALock:Boolean):TIGMPGroup;
Description: Find the address in the group cache
Transport The transport for the group to find
Address The address for the group to find
Lock If True then lock the found entry before returning
Note Addresses are passed in Host order

Caller must hold the Transport lock


function TIGMPProtocol.GetGroupByNext(APrevious:TIGMPGroup; ALock,AUnlock:Boolean):TIGMPGroup;
Description: To be documented
Note None documented


function TIGMPProtocol.AddGroup(ATransport:TIGMPProtocolTransport; const AAddress:TInAddr; const AHardware:THardwareAddress; ALock:Boolean):TIGMPGroup;
Description: Add an IP address and hardware address to the group cache
Transport The transport for the group to add
Address The IP address of the entry to add
Hardware The hardware address of the entry to add
Lock If True then lock the added entry before returning
Note Addresses are passed in Host order

Caller must hold the Transport lock


function TIGMPProtocol.RemoveGroup(ATransport:TIGMPProtocolTransport; const AAddress:TInAddr):Boolean;
Description: Remove an IP address from the group cache
Transport The transport for the group to remove
Address The IP address to remove
Note Addresses are passed in Host order

Caller must hold the Transport lock


procedure TIGMPProtocol.FlushGroups(All:Boolean);
Description: Flush groups from the group cache
All If True flush all groups, otherwise flush expired groups


function TIGMPProtocol.ProcessGroups:Boolean;
Description: Process periodic tasks for IGMP groups
Note None documented


function TIGMPProtocol.SelectCheck(ASource,ADest:PFDSet; ACode:Integer):Integer;
Description: To be documented
Source Source is the working set to check
Dest Dest is the set passed to Select


function TIGMPProtocol.SelectWait(ASocket:TProtocolSocket; ACode:Integer; ATimeout:LongWord):Integer;
Description: To be documented
Socket Socket is the single socket to check
Code Code is the type of check
Timeout Timeout is how long to wait


function TIGMPProtocol.SendPacket(ASocket:TProtocolSocket; ASource,ADest:Pointer; ASourcePort,ADestPort:Word; APacket:PPacketFragment; ASize,AFlags:Integer):Integer;
Description: Send a Packet by adding the Protocol Header and other details to the Data
Socket The socket to use for sending the packet
Source The source address of the packet (Host Order)
Dest The destination address of the packet (Host Order)
SourcePort The source port of the packet (Host Order)
DestPort The destination port of the packet (Host Order)
Packet The packet data to send
Size The size of the packet data in bytes
Flags Any protocol specific flags for sending
Note For IGMP the Data is the Header so the packet is not changed

Addresses are passed in Host order
Caller must hold the Socket lock


function TIGMPProtocol.Accept(ASocket:TProtocolSocket; ASockAddr:PSockAddr; AAddrLength:PInteger):TProtocolSocket;
Description: BSD compatible Accept
Socket The socket to accept from
SockAddr The socket address (Network Order)
AddrLength The socket address length
Note SockAddr is passed in Network order

Caller must hold the Socket lock


function TIGMPProtocol.Bind(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer;
Description: BSD compatible Bind
Socket The socket to bind
SockAddr The socket address (Network Order)
AddrLength The socket address length
Note Sets the LocalAddress for future Sends and Receives, Address can be specified as INADDR_ANY which allows Listening or auto assignment.

SockAddr is passed in Network order
Caller must hold the Socket lock


function TIGMPProtocol.CloseSocket(ASocket:TProtocolSocket):Integer;
Description: BSD compatible Close Socket
Socket The socket to close
Note Closes and removes the socket, does not perform Linger.

Caller must hold the Socket lock


function TIGMPProtocol.Connect(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; AAddrLength:Integer):Integer;
Description: BSD compatible Connect
Socket The socket to connect
SockAddr The socket address (Network Order)
AddrLength The socket address length
Note Sets the RemoteAddress of future Sends and Receives, if Bind has not been called then the LocalAddress will be set appropriately as well based on the route to the RemoteAddress.

SockAddr is passed in Network order
Caller must hold the Socket lock


function TIGMPProtocol.IoctlSocket(ASocket:TProtocolSocket; ACmd:DWORD; var AArg:u_long):Integer;
Description: BSD compatible IO Control Socket
Socket The socket to control
Cmd The socket command
Arg The command argument
Note Caller must hold the Socket lock


function TIGMPProtocol.GetPeerName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer;
Description: BSD compatible Get Peer Name (Remote)
Socket The socket to get from
SockAddr The socket address (Network Order)
AddrLength The socket address length
Note SockAddr is returned in Network order

Caller must hold the Socket lock


function TIGMPProtocol.GetSockName(ASocket:TProtocolSocket; var ASockAddr:TSockAddr; var AAddrLength:Integer):Integer;
Description: BSD compatible Get Sock Name (Local)
Socket The socket to get from
SockAddr The socket address (Network Order)
AddrLength The socket address length
Note SockAddr is returned in Network order

Caller must hold the Socket lock


function TIGMPProtocol.GetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer;
Description: BSD compatible Get Socket Option
Socket The socket to get the option from
Level The protocol level for the option
OptName The name of the option to get
OptValue The value of the option
OptLength The length of the option
Note Caller must hold the Socket lock


function TIGMPProtocol.Listen(ASocket:TProtocolSocket; ABacklog:Integer):Integer;
Description: BSD compatible Listen
Socket The socket to listen on
Backlog Queue depth for accepted connections
Note Caller must hold the Socket lock


function TIGMPProtocol.Recv(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer;
Description: BSD compatible Receive
Socket The socket to receive from
Buffer Buffer for received data
Length Length of buffer in bytes
Flags Protocol specific receive flags
Note Caller must hold the Socket lock


function TIGMPProtocol.RecvFrom(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AFromAddr:TSockAddr; var AFromLength:Integer):Integer;
Description: BSD compatible Receive From
Socket The socket to receive from
Buffer Buffer for received data
Length Length of buffer in bytes
Flags Protocol specific receive flags
FromAddr The address the data was received from (Network Order)
FromLength The length of the address
Note SockAddr is returned in Network order

Caller must hold the Socket lock


function TIGMPProtocol.Send(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer):Integer;
Description: BSD compatible Send
Socket The socket to send to
Buffer Buffer for data to send
Length Length of buffer in bytes
Flags Protocol specific send flags
Note Caller must hold the Socket lock


function TIGMPProtocol.SendTo(ASocket:TProtocolSocket; var ABuffer; ALength,AFlags:Integer; var AToAddr:TSockAddr; AToLength:Integer):Integer;
Description: BSD compatible Send To
Socket The socket to send to
Buffer Buffer for data to send
Length Length of buffer in bytes
Flags Protocol specific send flags
ToAddr The socket address to send to (Network Order)
ToLength The length of the socket address
Note SockAddr is passed in Network order

Caller must hold the Socket lock


function TIGMPProtocol.SetSockOpt(ASocket:TProtocolSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer;
Description: BSD compatible Set Socket Option
Socket The socket to set the option for
Level The protocol level for the option
OptName The name of the option to set
OptValue The value of the option
OptLength The length of the option
Note Caller must hold the Socket lock


function TIGMPProtocol.Shutdown(ASocket:TProtocolSocket; AHow:Integer):Integer;
Description: BSD compatible Shutdown
Socket The socket to shutdown
How The direction to shutdown the socket
Note Shutdown does not result in CloseSocket so Closed must not get set

Caller must hold the Socket lock


function TIGMPProtocol.Socket(AFamily,AStruct,AProtocol:Integer):TProtocolSocket;
Description: BSD compatible Socket (Create a new socket)
Family Socket address family (eg AF_INET)
Struct Socket type (eg SOCK_DGRAM)
Protocol Socket protocol (eg IPPROTO_UDP)


function TIGMPProtocol.AddTransport(ATransport:TNetworkTransport):Boolean;
Description: Add a transport to this protocol
Transport The transport to add


function TIGMPProtocol.RemoveTransport(ATransport:TNetworkTransport):Boolean;
Description: Remove a transport from this protocol
Transport The transport to remove


function TIGMPProtocol.FindSocket(AFamily,AStruct,AProtocol:Word; ALocalAddress,ARemoteAddress:Pointer; ALocalPort,ARemotePort:Word; ABroadcast,AListen,ALock:Boolean; AState:LongWord):TProtocolSocket;
Description: Find a protocol socket based on all relevant parameters
Family Socket address family (eg AF_INET)
Struct Socket type (eg SOCK_DGRAM)
Protocol Socket protocol (eg IPPROTO_UDP)
LocalAddress Local transport address to match (Host Order)
RemoteAddress Remote transport address to match (Host Order)
LocalPort Local port to match (Host Order)
RemotePort Remote port to match (Host Order)
Broadcast If True then match broadcast addresses
Listen If True then match only listening sockets
Lock If True then lock the found entry before returning


procedure TIGMPProtocol.FlushSockets(All:Boolean);
Description: Flush sockets from the socket cache
All If True flush all sockets, otherwise flush expired sockets.


function TIGMPProtocol.StartProtocol:Boolean;
Description: Start this protocol ready for sending and receiving
Note None documented


function TIGMPProtocol.StopProtocol:Boolean;
Description: Stop this protocol ready for removal
Note None documented


function TIGMPProtocol.ProcessProtocol:Boolean;
Description: Process periodic tasks for this protocol
Note None documented


Return to Unit Reference