Skip to content

Commit

Permalink
Fix a bug - selecting wrong interface for live capture
Browse files Browse the repository at this point in the history
  • Loading branch information
odedshimon committed Aug 30, 2021
1 parent 34917a2 commit 40cf4c7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions BruteShark/PcapProcessor/Sniffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public void StartSniffing(CancellationToken ct)
if (selectedDevice is SharpPcap.LibPcap.LibPcapLiveDevice)
{
var livePcapDevice = selectedDevice as SharpPcap.LibPcap.LibPcapLiveDevice;
livePcapDevice.Open(PromisciousMode ? SharpPcap.DeviceModes.Promiscuous : SharpPcap.DeviceModes.None);
livePcapDevice.Open(mode: PromisciousMode ? SharpPcap.DeviceModes.Promiscuous : SharpPcap.DeviceModes.None
| DeviceModes.DataTransferUdp
| DeviceModes.NoCaptureLocal);
}
else
{
Expand Down Expand Up @@ -98,7 +100,7 @@ public void StartSniffing(CancellationToken ct)
// Raise events for unfinished sessions.
HandleUnfinishedSessions();
}

private void SetupBpfFilter(ICaptureDevice selectedDevice)
{
if (this.Filter != null && this.Filter != string.Empty)
Expand Down Expand Up @@ -136,14 +138,10 @@ private void ClearOldSniffingsData()

private SharpPcap.ICaptureDevice GetSelectedDevice()
{
var availiableDevices = CaptureDeviceList.Instance;

if (!AvailiableDevicesNames.Contains(this.SelectedDeviceName))
{
throw new Exception($"No such device {SelectedDeviceName}");
}

return availiableDevices[AvailiableDevicesNames.IndexOf(this.SelectedDeviceName)];
return CaptureDeviceList.Instance
.Select(d => (PcapDevice)d)
.Where(d => d.Interface.FriendlyName == this.SelectedDeviceName)
.FirstOrDefault();
}

private void StartPacketProcessingThread()
Expand Down

0 comments on commit 40cf4c7

Please sign in to comment.