Skip to content

Commit

Permalink
Merge pull request #101 from odedshimon/issue-99-wireless-capture-bug
Browse files Browse the repository at this point in the history
Fix a bug - selecting wrong interface for live capture
  • Loading branch information
odedshimon authored Aug 30, 2021
2 parents 34917a2 + 40cf4c7 commit 0c1efc9
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 0c1efc9

Please sign in to comment.