Skip to content

Commit

Permalink
Add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed May 27, 2021
1 parent c10d892 commit f63a843
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Eap/EapAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading;
using SharpPcap;
using SharpPcap.LibPcap;
using SysuH3C.Utils;
using static SysuH3C.Utils.AssertHelpers;

Expand All @@ -19,7 +20,7 @@ public sealed class EapAuth : IDisposable
private readonly ReadOnlyMemory<byte> userName;
private readonly ReadOnlyMemory<byte> password;
private readonly ReadOnlyMemory<byte> paddedPassword;
private readonly ILiveDevice device;
private readonly LibPcapLiveDevice device;
private readonly EapOptions options;
private bool disposed = false;
private bool hasLogOff = false;
Expand All @@ -28,21 +29,23 @@ public EapAuth(EapOptions options)
{
this.options = options;

var devices = CaptureDeviceList.Instance;
var devices = LibPcapLiveDeviceList.Instance;
var device = devices.FirstOrDefault(i => i.Name == options.DeviceName);
if (device is null)
{
throw new FileNotFoundException($"Network device '{options.DeviceName}' doesn't exist. \nAvailable interfaces: \nDevice Name (Device Description) \n{devices.Select(i => $"{i.Name} ({i.Description})").Aggregate((a, n) => $"{a}\n{n}")}");
}

ethernetHeader = PacketHelpers.GetEthernetHeader(device.MacAddress.GetAddressBytes(), paeGroupAddr, 0x888e);
device.Open(DeviceModes.None);
this.device = device;

device.Open();
device.Filter = "not (tcp or udp or arp or rarp or ip or ip6)";

this.device = device;
userName = Encoding.ASCII.GetBytes(options.UserName);
password = Encoding.ASCII.GetBytes(options.Password.Length > 16 ? options.Password[0..16] : options.Password);
paddedPassword = password.ToArray().Concat(Enumerable.Repeat<byte>(0, 16 - password.Length)).ToArray();

ThreadPool.UnsafeQueueUserWorkItem(EapWorker, new EapWorkerState(), false);
}

Expand Down

0 comments on commit f63a843

Please sign in to comment.