This event handler is called immediately after a packet is read from a CAP file, and if you have set
a BPF filter, this event handler is executed only for packets, passed by BPF filter.
Please use statistics to make sure that your application does not lose any packets.
Also, you should take into account that OnPacketReceive event handler is called in the context of a
thread, created by Packet Sniffer SDK library.
We strongly recommend you to do nothing related to the data displaying in this event handler. If
the traffic is high, such actions may lead to the hanging of the application and packets loss.
OnPacketReceive event handler example:
procedure TForm1.HNAdapterOnPacketReceive(Sender: TObject;
ThParam, hPacket, pPacketData: Pointer; IncPacketSize: DWORD);
var
pEth: PETHERNET_HEADER;
EthType: Word;
pArp: PARP_HEADER;
begin
HNPacket1.Handle := hPacket;
if (HNPacket1.MediumType <> atEthernet) then Exit;
pEth := PETHERNET_HEADER(pPacketData);
EthType := htons(pEth^.EthType);
...
if(EthType = ETHERTYPE_ARP) then
begin
pArp := PARP_HEADER(@PByteArray(pPacketData)^[sizeof(ETHERNET_HEADER)]);
MoveMemory(@DestMacAddr[0],@pArp^.Sndr_Hw_Addr[0],6);
SetEvent(RecvArpPacket);
Exit;
end;
...
end;