Question - How can I use this package to drop packets according to a filter?
CMC01 opened this issue · 3 comments
Hi,
I've been using Clumsy for some time to perform manual testing against a WebRTC implementation. Running these tests each release has now become a big slow down in our release process so I'm investigating whether I can use a package like this one in conjunction with Selenium to simulate a user with an inconsistent local network.
I've been playing around with the sandbox example as well as other projects you've linked which use this package but I cannot get my head around where I am going wrong- I feel I must be fundamentally misunderstanding at least part of the implementation. When debugging, it appears that WinDivertSharp is not sniffing any traffic (hence, when I try to drop traffic nothing is dropped). I've included my approach below, do you have any pointers or are there any further examples/documents I can review to further my understanding?
public static IntPtr BlockTraffic()
{
string filter = "tcp";
Console.WriteLine("About to start blocking traffic");
var handle = WinDivert.WinDivertOpen(filter, WinDivertLayer.Network, 0 , WinDivertOpenFlags.Drop);
return handle;
}
public static void UnblockTraffic(IntPtr handle)
{
Console.WriteLine("About to stop blocking traffic");
WinDivert.WinDivertClose(handle);
}
Since this isn't specific to the c# code, I would recommend posting your Q on stackoverflow. The windivert author monitors certain tags.
You're going to need to Marshal.GetLastWin32Error() to find the problem. Are you running as administrator?
Thank you so much, I've managed to get this working now.
using System.Runtime.InteropServices;
...
IntPtr handle = NetworkUtilities.BlockTraffic();
int error = Marshal.GetLastWin32Error();
Console.WriteLine("The last Win32 Error was: " + error);
This returns error code 5, ie. Access is denied. Your suggestion was correct- I wasn't running the project as administrator.
Very much looking forward to using this package in our test projects from this point forwards!