basil00 / Divert

WinDivert: Windows Packet Divert
https://reqrypt.org/windivert.html
Other
2.32k stars 491 forks source link

api suggestion #319

Closed xljiulang closed 1 year ago

xljiulang commented 1 year ago

Hi @basil00 ! With your help, I have successfully wrapped this project as an asynchronous call library for the Dotnet platform. But in the use of upper-level projects, we often need more api like WinDivertHelperCalcChecksums to calculate and modify WINDIVERT_ADDRESS, such as recalculating IfIdx, OutboundFlag, LoopbackFlag when the IP changes, I hope these divert projects can provide api to complete these calculations.

WinDivertPacket Api Description Divert Api
bool CalcChecksums(WinDivertAddress,
ChecksumsFlag ) 重新计算和修改相关的Checksums WinDivertHelperCalcChecksums
bool CalcNetworkIfIdx(WinDivertAddress ) 根据IP地址重新计算和修改addr的Network->IfIdx lack
bool CalcOutboundFlag(WinDivertAddress) 根据IP地址和addr.Network->IfIdx重新计算和修改addr的Outbound标记 lack
bool CalcLoopbackFlag(WinDivertAddress) 根据IP地址重新计算和修改addr的Loopback标记 lack
bool DecrementTTL() ttl减1 WinDivertHelperDecrementTTL
int GetHashCode() 获取包的哈希 WinDivertHelperHashPacket
int GetHashCode(long) 获取包的哈希 WinDivertHelperHashPacket
WinDivertParseResult GetParseResult() 获取包的解析结果 WinDivertHelperParsePacket
basil00 commented 1 year ago
  1. The IfIdx value cannot be calculated directly by WinDivert, but can be calculated using the Windows "IP Helper" API. The WinDivert dll could provide a wrapper, but >99% do not need this functionality so the additional dependency is not justified.
  2. The "outbound" and "loopback" flags are actually determined by Windows and not WinDivert. There are some corner cases as to what these flags should be, which is why the current API does not attempt to guess/reconstruct the values.