ravahn / machina

Network capture library for realtime TCP/IP decoding from a windows application. Includes an extension library to support FFXIV data capture.
GNU General Public License v3.0
212 stars 77 forks source link

MessageSent callback does not trigger when UseSocketFilter = true #7

Open highlyunavailable opened 5 years ago

highlyunavailable commented 5 years ago

If I set the UseSocketFilter property of an FFXIVNetworkMonitor to true, the callback for MessageSent never triggers. I'm using raw sockets, not winpcap.

I've ensured that the app is allowed through the firewall and there are no errors in the trace log. At a deeper level, it looks like ProcessSentMessage is never called because no packets are ever returned for the sent side of the connection. Is this a limitation of UseSocketFilter or is there further configuration I need to do?

ravahn commented 2 years ago

I've finally tracked this down. The reason for this behavior is because the code is using winsock Connect() function to filter on the remote IP when UseSocketFilter is set to true. However, according to documentation https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2?redirectedfrom=MSDN:

If a foreign address is defined for the socket, it should correspond to the source address as specified in the IP header of the received datagram

For raw sockets, the received packets will have the expected remote ip as the source address. Unfortunately, packets originating from the game will have source address = local ip, and so this is the reason these packets are not available when this feature is turned on.

I will need to consider a larger change to Machina to resolve this - probably creating multiple raw sockets, one for each direction, when this flag is enabled.