Exemplo n.º 1
0
        internal static void CheckExchange(IInjectionDevice sender, ICaptureDevice receiver)
        {
            const int PacketsCount = 10;
            var       packets      = new List <RawCapture>();
            var       statuses     = new List <CaptureStoppedEventStatus>();

            void Receiver_OnPacketArrival(object s, PacketCapture e)
            {
                packets.Add(e.GetPacket());
            }

            void Receiver_OnCaptureStopped(object s, CaptureStoppedEventStatus status)
            {
                statuses.Add(status);
            }

            // Configure sender
            sender.Open();

            // Configure receiver
            receiver.Open(DeviceModes.Promiscuous);
            receiver.Filter            = "ether proto 0x1234";
            receiver.OnPacketArrival  += Receiver_OnPacketArrival;
            receiver.OnCaptureStopped += Receiver_OnCaptureStopped;
            receiver.StartCapture();

            // Send the packets
            var packet = EthernetPacket.RandomPacket();

            packet.DestinationHardwareAddress = PhysicalAddress.Parse("FFFFFFFFFFFF");
            packet.Type = (EthernetType)0x1234;
            for (var i = 0; i < PacketsCount; i++)
            {
                sender.SendPacket(packet);
            }
            // Wait for packets to arrive
            Thread.Sleep(2000);
            receiver.StopCapture();

            // Checks
            Assert.That(packets, Has.Count.EqualTo(PacketsCount));
            Assert.That(statuses, Has.Count.EqualTo(1));
            Assert.AreEqual(statuses[0], CaptureStoppedEventStatus.CompletedWithoutError);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sends a raw packet through this device
 /// </summary>
 /// <param name="p">The packet to send</param>
 /// <param name="size">The number of bytes to send</param>
 public static void SendPacket(this IInjectionDevice device, Packet p, int size)
 {
     device.SendPacket(p.Bytes, size);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Sends a raw packet through this device
 /// </summary>
 /// <param name="p">The packet to send</param>
 public static void SendPacket(this IInjectionDevice device, Packet p)
 {
     device.SendPacket(p.Bytes);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sends a raw packet through this device
 /// </summary>
 /// <param name="p">The packet bytes to send</param>
 /// <param name="size">The number of bytes to send</param>
 public static void SendPacket(this IInjectionDevice device, byte[] p, int size)
 {
     device.SendPacket(new ReadOnlySpan <byte>(p, 0, size));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Send a raw packet through this device
 /// </summary>
 /// <param name="device"></param>
 /// <param name="p"></param>
 /// <param name="header"></param>
 public static void SendPacket(this IInjectionDevice device, RawCapture p, ICaptureHeader header = null)
 {
     device.SendPacket(new ReadOnlySpan <byte>(p.Data), header);
 }