Open verdie-g opened 3 months ago
@verdie-g
// 1. This works fine
device.SendPacket(capture.GetPacket(), capture.Header);
This call preserve the metadata of the received packet, the metadata include the direction of the packet, what interface it was received on, etc
the metadata is stored in the capture header.
// 2. This doesn't work fine
device.SendPacket(capture.GetPacket());
In this case, you took the packet data, and removed all associated metadata, in this case sharppcap will use the default configuration libpcap driver would use, this means it will assume the packet is outgoing from the system, which may not be the case in the original metadata.
it will assume the packet is outgoing from the system
Could you help me understand where in the code that assumption is made.
if (IpHelper.IsOutbound((int)addr.IfIdx, src, dst))
{
addr.Flags |= WinDivertPacketFlags.Outbound;
}
here it looks like it can know if the packet is inbound or outbound.
@verdie-g what ip addresses does the interferences and the packet have?
os version?
windivert driver version?
Remote ip: 54.171.35.223 OS: 11 23H2 Windivert: 2.2.2
@verdie-g I can't reproduce the problem, the logic implemented in sharppcap does a "Best Effort" guess of what interface should be used, and uses GetBestInterfaceEx API
@basil00 Is there a better API to infer the interface from the packet address?
It's fine, I realized later that using WinDivertSend
without the original WINDIVERT_ADDRESS
was probably a bad idea.
When I use
WinDivertDevice.SendPacket
without specifying anICaptureHeader
, the wrong interface is chosen.After some debugging, I saw that
1.
usesIfIdx=0, SubIfIdx=7
but2.
usesIfIdx=7, SubIfIdx=0 (unset)
.Does this code do the best it can to get the right interface or do you think it could be improved? https://github.com/dotpcap/sharppcap/blob/15c95ecb2d7150b92a31dc6a2a3114aa4c6b683c/SharpPcap/WinDivert/WinDivertDevice.cs#L280-L303
I'm on Windows 11 23H2