My Account account_circle

Among filtering out packets based on their content like in the previous example, another possible usage of the filter event in SmartInspect would be to cancel packets which exceed a certain maximum packet size. This can be useful to reduce bandwidth or to keep log files small. An example implementation looks like:

using Gurock.SmartInspect;

public class PacketSizeFilter
{
    private int fMaximum;

    public PacketSizeFilter(int maximum)
    {
        this.fMaximum = maximum;
    }

    public void Run(object sender, FilterEventArgs args)
    {
        if (args.Packet.Size > this.fMaximum)
        {
            args.Cancel = true;
        }
    }
}


public class Program
{
    static void Main(string[] args)
    {
        // ...

        // Only allow packets with a maximum size of 1KB
        PacketSizeFilter filter = new PacketSizeFilter(1024);
        SiAuto.Si.Filter += new
            FilterEventHandler(filter.Run);

        // ...
    }
}

The Run method of the PacketSizeFilter class is the actual event handler for the Filter event and filters out every packet which exceeds a certain, user-defined packet size limit. In this case, every packet which is bigger than 1024 bytes will be canceled.

How useful was this post?

Click on a star to rate it!

Stay ahead in Test Management.

Follow us on social media!

Help us improve this page!

What problem are you trying to solve?