Home › Forums › Discussions › Support › Modify TTL of the packets › Re: Same here, at Sofia
May 1, 2006 at 3:29 pm
#5995
Same here, at Sofia… I can’t use inet on my laptop brought from work. Simple Windows ICS from my desktop PC doesn’t work so I had to play with the NTKernel goodies. Really nice libs. Thanks guys.
Let’s go to implementation:
1. Start with the PassThru example
2. Add some checks on the received packet
3. ttl=5
4. checksum=0
5. checksum=RecalcChecksum(ipheader, ipheaderlen)
I had the most problems on the checksum as different functions found on the net work with different params and it was hard to set it correctly. Now it works 🙂
some delphi code:
while not Terminated and (ReadPacket(hFilt, @ReadRequest) <> 0) do
begin
try
pEtherHeader := TEtherHeaderPtr(@Buffer.m_IBuffer);
// Check for IP protocol and OnReceive flag
if ntohs(pEtherHeader.h_proto) = ETH_P_IP then
begin
pIPHeader := TIPHeaderPtr(Integer(pEtherHeader) +
SizeOf(TEtherHeader));
// Check if TTL causes problems
if pIPHeader.TTL <= ERR_TTL then
begin
pIPHeader.TTL := NEW_TTL;
pIPHeader.Checksum := 0;
pIPHeader.Checksum := htons(
Checksum(PWord(pIPHeader),
(SizeOf(TIPHeader) - SizeOf(DWORD)) div 2));
end;
end;
finally
// Send the request down the line
if Buffer.m_dwDeviceFlags = PACKET_FLAG_ON_SEND then
// Place packet on the network interface
SendPacketToAdapter(hFilt, @ReadRequest)
else
// Indicate packet to MSTCP
SendPacketToMstcp(hFilt, @ReadRequest);
end;
end;
end;