-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WinDivertDevice.SendPacket wrongly infers interface index #527
Comments
// 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. |
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 |
@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 |
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?
sharppcap/SharpPcap/WinDivert/WinDivertDevice.cs
Lines 280 to 303 in 15c95ec
I'm on Windows 11 23H2
The text was updated successfully, but these errors were encountered: