procedure snoopSendTCPBlock(Pcap: PPcap;
MyMac: PMACADDR;
ETHHdr: PETH_HDR;
IPHdr: PIP_HDR;
TCPHdr: PTCP_HDR);
const
TCP_BLOCK_DATA_SIZE = sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR);
var
MyBuffer:
array [0 .. TCP_BLOCK_DATA_SIZE - 1]
of Char;
MyETHHdr: PETH_HDR;
MyIPHdr: PIP_HDR;
MyTCPHdr: PTCP_HDR;
TCPDataLen: Integer;
begin
// My Hdr
MyETHHdr := @MyBuffer[0];
MyIPHdr := PIP_HDR(UINT32(MyETHHdr) + sizeof(ETH_HDR));
MyTCPHdr := PTCP_HDR(UINT32(MyIPHdr) + sizeof(IP_HDR));
// Set Ethernet Hdr
MyETHHdr^.Destination := ETHHdr^.Destination;
MyETHHdr^.Source := MyMac^;
MyETHHdr^.Protocol := ETHHdr^.Protocol;
// Set IP Hdr
MyIPHdr^.VerLen := IPHdr^.VerLen;
MyIPHdr^.Service := IPHdr^.Service;
MyIPHdr^.Length := ntohs(sizeof(IP_HDR) + sizeof(TCP_HDR));
MyIPHdr^.Ident := htons(ntohs(IPHdr^.Ident) + 1);
MyIPHdr^.FlagOff := htons(16384);
MyIPHdr^.TimeLive := 44;
MyIPHdr^.Protocol := PROTO_TCP;
MyIPHdr^.Source := IPHdr^.Source;
MyIPHdr^.Destination := IPHdr^.Destination;
// Set TCPHdr
MyTCPHdr^.Source := TCPHdr^.Source;
MyTCPHdr^.Destination := TCPHdr^.Destination;
if snoopIsTCPData(IPHdr, TCPHdr,
nil, @TCPDataLen)
then
begin
MyTCPHdr^.Seq := htonl(ntohl(TCPHdr^.Seq) + TCPDataLen);
end else
begin
MyTCPHdr^.Seq := TCPHdr^.Seq;
end;
MyTCPHdr^.Ack := TCPHdr^.Ack;
MyTCPHdr^.Off_Rsvd := $50;
MyTCPHdr^.Rsvd_Flags := $04;
MyTCPHdr^.Window := 0;
MyTCPHdr^.UrgPoint := 0;
// Calculate Checksum
MyTCPHdr^.Checksum := htons(snoopTCPChecksum(MyIPHdr, MyTCPHdr));
MyIPHdr^.Checksum := htons(snoopIPChecksum(MyIPHdr));
// SendPacket
snoopSendPacket(Pcap, @MyBuffer[0], TCP_BLOCK_DATA_SIZE);
end;