Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	Mono.Nat/.gitignore
  • Loading branch information...
commit 66ba66615991301bc9b85bbb5fcdcf4b7814aa48 2 parents e9d67b7 + bd2261e
@seuffert authored
Showing with 3,917 additions and 13,569 deletions.
  1. +1 −1  Mono.Nat/.gitignore
  2. +2 −2 Mono.Nat/AssemblyInfo.cs
  3. +0 −1  Mono.Nat/ISearcher.cs
  4. +43 −10 Mono.Nat/Mono.Nat.csproj
  5. +9 −6 Mono.Nat/NatUtility.cs
  6. +44 −15 Mono.Nat/Pmp/PmpNatDevice.cs
  7. +63 −15 Mono.Nat/PmpSearcher.cs
  8. +10 −1 Mono.Nat/UpnpSearcher.cs
  9. +1 −1  PacketDotNet/AssemblyInfo.cs
  10. +2 −6 PacketDotNet/EthernetPacket.cs
  11. +0 −67 PacketDotNet/IPProtocol.cs
  12. +0 −1  PacketDotNet/IPv4Packet.cs
  13. +0 −1  PacketDotNet/IPv6Packet.cs
  14. +0 −4 PacketDotNet/IpPacket.cs
  15. +1 −2  PacketDotNet/LinuxSLLPacket.cs
  16. +1 −2  PacketDotNet/PPPPacket.cs
  17. +2 −3 PacketDotNet/PPPoEPacket.cs
  18. +0 −43 PacketDotNet/Packet.cs
  19. +2 −4 PacketDotNet/PacketDotNet.csproj
  20. +0 −13 PacketDotNet/PacketDotNet.csproj.user
  21. +0 −122 PacketDotNet/RawPacket.cs
  22. +0 −10 PacketDotNet/TransportProtocols.cs
  23. +1 −1  SharpPcap/ARP.cs
  24. +9 −9 SharpPcap/AirPcap/AirPcapDevice.cs
  25. +1 −1  SharpPcap/AssemblyInfo.cs
  26. +4 −4 SharpPcap/CaptureEventArgs.cs
  27. +0 −42 SharpPcap/CaptureMode.cs
  28. +7 −2 SharpPcap/ICaptureDevice.cs
  29. +20 −0 SharpPcap/LibPcap/LibPcapLiveDevice.cs
  30. +0 −23 SharpPcap/LibPcap/LibPcapLiveDeviceList.cs
  31. +47 −13 SharpPcap/LibPcap/PcapDevice.cs
  32. +0 −330 SharpPcap/LivePcapDevice.cs
  33. +0 −232 SharpPcap/LivePcapDeviceList.cs
  34. +0 −125 SharpPcap/OfflinePcapDevice.cs
  35. +0 −92 SharpPcap/PcapAddress.cs
  36. +0 −622 SharpPcap/PcapDevice.cs
  37. +0 −399 SharpPcap/PcapDeviceCaptureLoop.cs
  38. +0 −172 SharpPcap/PcapHeader.cs
  39. +0 −182 SharpPcap/PcapInterface.cs
  40. +0 −126 SharpPcap/PcapStatistics.cs
  41. +0 −293 SharpPcap/PcapUnmanagedStructures.cs
  42. +11 −13 {PacketDotNet → SharpPcap}/PosixTimeval.cs
  43. +90 −0 SharpPcap/RawCapture.cs
  44. +0 −302 SharpPcap/SafeNativeMethods.cs
  45. +0 −196 SharpPcap/SendQueue.cs
  46. +0 −41 SharpPcap/SendQueueTransmitModes.cs
  47. +2 −0  SharpPcap/SharpPcap.csproj
  48. +0 −13 SharpPcap/SharpPcap.csproj.user
  49. +0 −173 SharpPcap/Sockaddr.cs
  50. +0 −56 SharpPcap/StatisticsModeEventArgs.cs
  51. +0 −31 SharpPcap/StatisticsModeEventHandler.cs
  52. +0 −74 SharpPcap/StatisticsModePacket.cs
  53. +1 −1  SharpPcap/WinPcap/SendQueue.cs
  54. +2 −2 SharpPcap/WinPcap/StatisticsModeEventArgs.cs
  55. +2 −2 SharpPcap/WinPcap/StatisticsModePacket.cs
  56. +27 −2 SharpPcap/WinPcap/WinPcapDevice.cs
  57. +234 −15 SharpPcap/docs/Api/SharpPcap.xml
  58. +84 −0 XBSlink Installer/VersionCompare.nsh
  59. BIN  XBSlink Installer/WinPcap_4_1_2.exe
  60. +16 −3 XBSlink Installer/XBSlink_installer_MUI2.nsi
  61. +25 −7 XBSlink Installer/XBSlink_license.txt
  62. BIN  XBSlink Installer/winpcap_setup.exe
  63. +0 −8 XBSlink.sln
  64. +53 −34 XBSlink/CommandLine.cs
  65. +15 −19 XBSlink/DebugWindow.Designer.cs
  66. +89 −32 XBSlink/DebugWindow.cs
  67. +3 −0  XBSlink/DebugWindow.resx
  68. +463 −219 XBSlink/Form1.Designer.cs
  69. +609 −242 XBSlink/Form1.cs
  70. +2 −2 XBSlink/Form1.resx
  71. +2 −2 XBSlink/Properties/AssemblyInfo.cs
  72. +63 −8 XBSlink/Properties/Resources.Designer.cs
  73. +24 −0 XBSlink/Properties/Resources.resx
  74. +278 −23 XBSlink/Properties/Settings.Designer.cs
  75. +74 −6 XBSlink/Properties/Settings.settings
  76. +28 −0 XBSlink/Settings.cs
  77. +9 −4 XBSlink/XBSlink.csproj
  78. +82 −0 XBSlink/XBSlink.exe.config
  79. BIN  XBSlink/about_xbslink.rtf
  80. +80 −1 XBSlink/app.config
  81. BIN  XBSlink/error_16.png
  82. BIN  XBSlink/ok_16.png
  83. BIN  XBSlink/warning_16.png
  84. +7 −3 XBSlink/xbs_chat.cs
  85. +37 −27 XBSlink/xbs_cloudlist.cs
  86. +92 −17 XBSlink/xbs_messages.cs
  87. +697 −0 XBSlink/xbs_nat.cs
  88. +45 −86 XBSlink/xbs_natstun.cs
  89. +113 −23 XBSlink/xbs_node.cs
  90. +31 −14 XBSlink/xbs_node_list.cs
  91. +6 −2 XBSlink/xbs_node_message.cs
  92. +14 −103 XBSlink/xbs_settings.cs
  93. +159 −67 XBSlink/xbs_sniffer.cs
  94. +78 −66 XBSlink/xbs_udp_listener.cs
  95. +0 −4 stunlib/.gitignore
  96. +0 −257 stunlib/IO/Base64.cs
  97. +0 −5,910 stunlib/LumiSoft.Net
  98. +0 −23 stunlib/Net.sln
  99. +0 −938 stunlib/Net_Utils.cs
  100. +0 −33 stunlib/Properties/AssemblyInfo.cs
  101. +0 −350 stunlib/STUN/Client/STUN_Client.cs
  102. +0 −59 stunlib/STUN/Client/STUN_NetType.cs
  103. +0 −49 stunlib/STUN/Client/STUN_Result.cs
  104. +0 −684 stunlib/STUN/Message/STUN_Message.cs
  105. +0 −42 stunlib/STUN/Message/STUN_MessageType.cs
  106. +0 −59 stunlib/STUN/Message/STUN_t_ChangeRequest.cs
  107. +0 −52 stunlib/STUN/Message/STUN_t_ErrorCode.cs
  108. +0 −113 stunlib/stunlib.csproj
  109. +0 −59 stunlib/stunlib.csproj.user
View
2  Mono.Nat/.gitignore
@@ -1,4 +1,4 @@
/bin/
/obj/
/Mono.Nat.pidb
-/*.csproj.user
+/*.Nat.csproj.user
View
4 Mono.Nat/AssemblyInfo.cs
@@ -13,7 +13,7 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("c8e81e95-9f15-4eb8-8982-3d2c9cd95dee")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: CLSCompliant(false)]
View
1  Mono.Nat/ISearcher.cs
@@ -14,7 +14,6 @@ internal interface ISearcher
event EventHandler<DeviceEventArgs> DeviceLost;
void Search();
- IPEndPoint SearchEndpoint { get; }
void Handle(IPAddress localAddress, byte[] response, IPEndPoint endpoint);
DateTime NextSearch { get; }
}
View
53 Mono.Nat/Mono.Nat.csproj
@@ -8,30 +8,44 @@
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>Mono.Nat</AssemblyName>
<RootNamespace>Mono.Nat</RootNamespace>
- <ProductVersion>9.0.30729</ProductVersion>
+ <ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <UpgradeBackupLocation>
- </UpgradeBackupLocation>
+ <OldToolsVersion>2.0</OldToolsVersion>
+ <UpgradeBackupLocation />
<TargetFrameworkProfile />
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>false</DebugSymbols>
+ <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>TRACE;DEBUG</DefineConstants>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>4</WarningLevel>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputType>Library</OutputType>
<RootNamespace>Mono.Nat</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugSymbols>false</DebugSymbols>
- <DebugType>none</DebugType>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
@@ -80,7 +94,26 @@
<Compile Include="Upnp\UpnpNatDevice.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
+ <BootstrapperPackage Include=".NETFramework,Version=v4.0">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4 %28x86 und x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
+ <Visible>False</Visible>
+ <ProductName>Windows Installer 3.1</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
View
15 Mono.Nat/NatUtility.cs
@@ -36,7 +36,7 @@ namespace Mono.Nat
{
public static class NatUtility
{
- private static bool searching;
+ private static ManualResetEvent searching;
public static event EventHandler<DeviceEventArgs> DeviceFound;
public static event EventHandler<DeviceEventArgs> DeviceLost;
@@ -60,9 +60,11 @@ public static bool Verbose
static NatUtility()
{
+ searching = new ManualResetEvent(false);
+
controllers = new List<ISearcher>();
controllers.Add(UpnpSearcher.Instance);
- //controllers.Add(PmpSearcher.Instance);
+ controllers.Add(PmpSearcher.Instance);
foreach (ISearcher searcher in controllers)
{
@@ -93,13 +95,15 @@ private static void SearchAndListen()
{
while (true)
{
+ searching.WaitOne();
+
try
{
Receive(UpnpSearcher.Instance, UpnpSearcher.sockets);
Receive(PmpSearcher.Instance, PmpSearcher.sockets);
foreach (ISearcher s in controllers)
- if (s.NextSearch < DateTime.Now && searching)
+ if (s.NextSearch < DateTime.Now)
{
Log("Searching for: {0}", s.GetType().Name);
s.Search();
@@ -130,13 +134,12 @@ static void Receive (ISearcher searcher, List<UdpClient> clients)
public static void StartDiscovery ()
{
- searching = true;
+ searching.Set();
}
public static void StopDiscovery ()
{
- controllers.Clear();
- searching = false;
+ searching.Reset();
}
[Obsolete ("This method serves no purpose and shouldn't be used")]
View
59 Mono.Nat/Pmp/PmpNatDevice.cs
@@ -59,14 +59,28 @@ public override IPAddress GetExternalIP ()
public override IAsyncResult BeginCreatePortMap(Mapping mapping, AsyncCallback callback, object asyncState)
{
PortMapAsyncResult pmar = new PortMapAsyncResult (mapping.Protocol, mapping.PublicPort, PmpConstants.DefaultLeaseTime, callback, asyncState);
- CreatePortMap (pmar.Mapping, true);
+ ThreadPool.QueueUserWorkItem (delegate {
+ try {
+ CreatePortMap(pmar.Mapping, true);
+ pmar.Complete();
+ } catch (Exception e) {
+ pmar.Complete(e);
+ }
+ });
return pmar;
}
public override IAsyncResult BeginDeletePortMap (Mapping mapping, AsyncCallback callback, object asyncState)
{
PortMapAsyncResult pmar = new PortMapAsyncResult (mapping, callback, asyncState);
- CreatePortMap (pmar.Mapping, false);
+ ThreadPool.QueueUserWorkItem (delegate {
+ try {
+ CreatePortMap(pmar.Mapping, false);
+ pmar.Complete();
+ } catch (Exception e) {
+ pmar.Complete(e);
+ }
+ });
return pmar;
}
@@ -195,7 +209,7 @@ private void CreatePortMapAsync (object obj)
CreatePortMapAsyncState state = obj as CreatePortMapAsyncState;
UdpClient udpClient = new UdpClient ();
- CreatePortMapListenState listenState = new CreatePortMapListenState (state);
+ CreatePortMapListenState listenState = new CreatePortMapListenState (state, udpClient);
int attempt = 0;
int delay = PmpConstants.RetryDelay;
@@ -204,6 +218,7 @@ private void CreatePortMapAsync (object obj)
while (attempt < PmpConstants.RetryAttempts && !listenState.Success) {
udpClient.Send (state.Buffer, state.Buffer.Length, new IPEndPoint (localAddress, PmpConstants.ServerPort));
+ listenState.UdpClientReady.Set();
attempt++;
delay *= 2;
@@ -220,11 +235,21 @@ private void CreatePortMapListen (object obj)
{
CreatePortMapListenState state = obj as CreatePortMapListenState;
- UdpClient udpClient = new UdpClient (5351);
- IPEndPoint endPoint = new IPEndPoint (publicAddress, PmpConstants.ServerPort);
+ UdpClient udpClient = state.UdpClient;
+ state.UdpClientReady.WaitOne(); // Evidently UdpClient has some lazy-init Send/Receive race?
+ IPEndPoint endPoint = new IPEndPoint (localAddress, PmpConstants.ServerPort);
while (!state.Success) {
- byte[] data = udpClient.Receive (ref endPoint);
+ byte[] data;
+ try
+ {
+ data = udpClient.Receive(ref endPoint);
+ }
+ catch (SocketException)
+ {
+ state.Success = false;
+ return;
+ }
if (data.Length < 16)
continue;
@@ -238,13 +263,13 @@ private void CreatePortMapListen (object obj)
if (opCode == PmpConstants.OperationCodeUdp)
protocol = Protocol.Udp;
- short resultCode = BitConverter.ToInt16 (data, 2);
- int epoch = BitConverter.ToInt32 (data, 4);
+ short resultCode = IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, 2));
+ uint epoch = (uint)IPAddress.NetworkToHostOrder (BitConverter.ToInt32 (data, 4));
- short privatePort = BitConverter.ToInt16 (data, 8);
- short publicPort = BitConverter.ToInt16 (data, 10);
+ int privatePort = (ushort)IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, 8));
+ int publicPort = (ushort)IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, 10));
- int lifetime = BitConverter.ToInt32 (data, 12);
+ uint lifetime = (uint)IPAddress.NetworkToHostOrder (BitConverter.ToInt32 (data, 12));
if (resultCode != PmpConstants.ResultCodeSuccess) {
state.Success = false;
@@ -261,8 +286,9 @@ private void CreatePortMapListen (object obj)
//TODO: verify that the private port+protocol are a match
Mapping mapping = state.Mapping;
mapping.PublicPort = publicPort;
+ mapping.Protocol = protocol;
mapping.Expiration = DateTime.Now.AddSeconds (lifetime);
-
+
state.Success = true;
}
}
@@ -291,12 +317,15 @@ private class CreatePortMapAsyncState
private class CreatePortMapListenState
{
- internal bool Success;
+ internal volatile bool Success;
internal Mapping Mapping;
+ internal UdpClient UdpClient;
+ internal ManualResetEvent UdpClientReady;
- internal CreatePortMapListenState (CreatePortMapAsyncState state)
+ internal CreatePortMapListenState (CreatePortMapAsyncState state, UdpClient client)
{
- Mapping = state.Mapping;
+ Mapping = state.Mapping;
+ UdpClient = client; UdpClientReady = new ManualResetEvent(false);
}
}
}
View
78 Mono.Nat/PmpSearcher.cs
@@ -3,6 +3,7 @@
using System.Text;
using System.Net;
using Mono.Nat.Pmp;
+using System.Net.NetworkInformation;
using System.Net.Sockets;
namespace Mono.Nat
@@ -10,8 +11,8 @@ namespace Mono.Nat
internal class PmpSearcher : ISearcher
{
static PmpSearcher instance = new PmpSearcher();
- public static List<UdpClient> sockets = CreateSockets();
-
+ public static List<UdpClient> sockets;
+ static Dictionary<UdpClient, List<IPEndPoint>> gatewayLists;
public static PmpSearcher Instance
@@ -21,24 +22,66 @@ public static PmpSearcher Instance
private int timeout;
private DateTime nextSearch;
- private IPEndPoint searchEndpoint;
public event EventHandler<DeviceEventArgs> DeviceFound;
public event EventHandler<DeviceEventArgs> DeviceLost;
+ static PmpSearcher()
+ {
+ CreateSocketsAndAddGateways();
+ }
+
PmpSearcher()
{
timeout = 250;
- // FIXME: Should not hardcode the address - should read gateway address from
- // the NetworkInformation class - as in UpnpSearcher
- searchEndpoint = new IPEndPoint(IPAddress.Parse("192.168.0.1"), PmpConstants.ServerPort);
}
- private static List<UdpClient> CreateSockets()
+ private static void CreateSocketsAndAddGateways()
{
- // FIXME: Should do the same detection that UPnPSearch does.
- List<UdpClient> sockets = new List<UdpClient>();
- sockets.Add(new UdpClient(new IPEndPoint(IPAddress.Any, 0)));
- return sockets;
+ sockets = new List<UdpClient>();
+ gatewayLists = new Dictionary<UdpClient,List<IPEndPoint>>();
+
+ try
+ {
+ foreach (NetworkInterface n in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ IPInterfaceProperties properties = n.GetIPProperties();
+ List<IPEndPoint> gatewayList = new List<IPEndPoint>();
+
+ foreach (GatewayIPAddressInformation gateway in properties.GatewayAddresses)
+ {
+ if (gateway.Address.AddressFamily == AddressFamily.InterNetwork)
+ {
+ gatewayList.Add(new IPEndPoint(gateway.Address, PmpConstants.ServerPort));
+ }
+ }
+
+ if (gatewayList.Count > 0)
+ {
+ foreach (UnicastIPAddressInformation address in properties.UnicastAddresses)
+ {
+ if (address.Address.AddressFamily == AddressFamily.InterNetwork)
+ {
+ UdpClient client;
+
+ try
+ {
+ client = new UdpClient(new IPEndPoint(address.Address, 0));
+ }
+ catch (SocketException)
+ {
+ continue; // Move on to the next address.
+ }
+
+ gatewayLists.Add(client, gatewayList); sockets.Add(client);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception)
+ {
+ // NAT-PMP does not use multicast, so there isn't really a good fallback.
+ }
}
public void Search()
@@ -74,17 +117,22 @@ void Search (UdpClient client)
// The nat-pmp search message. Must be sent to GatewayIP:53531
byte[] buffer = new byte[] { PmpConstants.Version, PmpConstants.OperationCode };
- client.Send(buffer, buffer.Length, searchEndpoint);
+ foreach (IPEndPoint gatewayEndpoint in gatewayLists[client])
+ client.Send(buffer, buffer.Length, gatewayEndpoint);
}
- public IPEndPoint SearchEndpoint
+ bool IsSearchAddress(IPAddress address)
{
- get { return searchEndpoint; }
+ foreach (List<IPEndPoint> gatewayList in gatewayLists.Values)
+ foreach (IPEndPoint gatewayEndpoint in gatewayList)
+ if (gatewayEndpoint.Address.Equals(address))
+ return true;
+ return false;
}
public void Handle(IPAddress localAddress, byte[] response, IPEndPoint endpoint)
{
- if (!endpoint.Address.Equals(searchEndpoint.Address))
+ if (!IsSearchAddress(endpoint.Address))
return;
if (response.Length != 12)
return;
View
11 Mono.Nat/UpnpSearcher.cs
@@ -47,7 +47,16 @@ static List<UdpClient> CreateSockets()
foreach (UnicastIPAddressInformation address in n.GetIPProperties().UnicastAddresses)
{
if (address.Address.AddressFamily == AddressFamily.InterNetwork)
- clients.Add(new UdpClient(new IPEndPoint(address.Address, 0)));
+ {
+ try
+ {
+ clients.Add(new UdpClient(new IPEndPoint(address.Address, 0)));
+ }
+ catch
+ {
+ continue; // Move on to the next address.
+ }
+ }
}
}
}
View
2  PacketDotNet/AssemblyInfo.cs
@@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
-[assembly: AssemblyVersion("0.8.0")]
+[assembly: AssemblyVersion("0.9.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
View
8 PacketDotNet/EthernetPacket.cs
@@ -190,7 +190,7 @@ public EthernetPacket(ByteArraySegment bas)
header.Length = EthernetFields.HeaderLength;
// parse the encapsulated bytes
- payloadPacketOrData = ParseEncapsulatedBytes(header, Type, Timeval);
+ payloadPacketOrData = ParseEncapsulatedBytes(header, Type);
}
/// <summary>
@@ -203,15 +203,11 @@ public EthernetPacket(ByteArraySegment bas)
/// <param name="Type">
/// A <see cref="EthernetPacketType"/>
/// </param>
- /// <param name="Timeval">
- /// A <see cref="PosixTimeval"/>
- /// </param>
/// <returns>
/// A <see cref="PacketOrByteArraySegment"/>
/// </returns>
internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header,
- EthernetPacketType Type,
- PosixTimeval Timeval)
+ EthernetPacketType Type)
{
// slice off the payload
var payload = Header.EncapsulatedBytes();
View
67 PacketDotNet/IPProtocol.cs
@@ -1,67 +0,0 @@
-// ************************************************************************
-// Copyright (C) 2001, Patrick Charles and Jonas Lehmann *
-// Distributed under the Mozilla Public License *
-// http://www.mozilla.org/NPL/MPL-1.1.txt *
-// *************************************************************************
-
-using System;
-
-namespace PacketDotNet
-{
- /// <summary>
- /// String representation of an IP protocol value
- /// </summary>
- public class IPProtocol
- {
- /// <summary> Fetch a protocol description.</summary>
- /// <param name="code">the code associated with the message.
- /// </param>
- /// <returns> a message describing the significance of the IP protocol.
- /// </returns>
- public static System.String getDescription(int code)
- {
- System.Int32 c = (System.Int32) code;
- if (messages.ContainsKey(c))
- {
- return (System.String) messages[c];
- } else
- {
- return "unknown";
- }
- }
-
- /// <summary> 'Human-readable' IP protocol descriptions.</summary>
- private static System.Collections.Hashtable messages = new System.Collections.Hashtable();
-
- static IPProtocol()
- {
- messages[(System.Int32) IPProtocolType.IP] = "Dummy protocol for TCP";
- messages[(System.Int32) IPProtocolType.HOPOPTS] = "IPv6 Hop-by-Hop options";
- messages[(System.Int32) IPProtocolType.ICMP] = "Internet Control Message Protocol";
- messages[(System.Int32) IPProtocolType.IGMP] = "Internet Group Management Protocol";
- messages[(System.Int32) IPProtocolType.IPIP] = "IPIP tunnels";
- messages[(System.Int32) IPProtocolType.TCP] = "Transmission Control Protocol";
- messages[(System.Int32) IPProtocolType.EGP] = "Exterior Gateway Protocol";
- messages[(System.Int32) IPProtocolType.PUP] = "PUP protocol";
- messages[(System.Int32) IPProtocolType.UDP] = "User Datagram Protocol";
- messages[(System.Int32) IPProtocolType.IDP] = "XNS IDP protocol";
- messages[(System.Int32) IPProtocolType.TP] = "SO Transport Protocol Class 4";
- messages[(System.Int32) IPProtocolType.IPV6] = "IPv6 header";
- messages[(System.Int32) IPProtocolType.ROUTING] = "IPv6 routing header";
- messages[(System.Int32) IPProtocolType.FRAGMENT] = "IPv6 fragmentation header";
- messages[(System.Int32) IPProtocolType.RSVP] = "Reservation Protocol";
- messages[(System.Int32) IPProtocolType.GRE] = "General Routing Encapsulation";
- messages[(System.Int32) IPProtocolType.ESP] = "encapsulating security payload";
- messages[(System.Int32) IPProtocolType.AH] = "authentication header";
- messages[(System.Int32) IPProtocolType.ICMPV6] = "ICMPv6";
- messages[(System.Int32) IPProtocolType.NONE] = "IPv6 no next header";
- messages[(System.Int32) IPProtocolType.DSTOPTS] = "IPv6 destination options";
- messages[(System.Int32) IPProtocolType.MTP] = "Multicast Transport Protocol";
- messages[(System.Int32) IPProtocolType.ENCAP] = "Encapsulation Header";
- messages[(System.Int32) IPProtocolType.PIM] = "Protocol Independent Multicast";
- messages[(System.Int32) IPProtocolType.COMP] = "Compression Header Protocol";
- messages[(System.Int32) IPProtocolType.RAW] = "Raw IP Packet";
-// messages[(System.Int32) IPProtocolType.INVALID] = "INVALID IP";
- }
- }
-}
View
1  PacketDotNet/IPv4Packet.cs
@@ -543,7 +543,6 @@ public IPv4Packet(ByteArraySegment bas)
var payload = header.EncapsulatedBytes(PayloadLength);
payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload,
NextHeader,
- Timeval,
this);
}
View
1  PacketDotNet/IPv6Packet.cs
@@ -347,7 +347,6 @@ public IPv6Packet(ByteArraySegment bas)
var payload = header.EncapsulatedBytes(PayloadLength);
payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload,
NextHeader,
- Timeval,
this);
}
View
4 PacketDotNet/IpPacket.cs
@@ -252,9 +252,6 @@ public IpPacket()
/// <param name="ProtocolType">
/// A <see cref="IPProtocolType"/>
/// </param>
- /// <param name="Timeval">
- /// A <see cref="PosixTimeval"/>
- /// </param>
/// <param name="ParentPacket">
/// A <see cref="Packet"/>
/// </param>
@@ -263,7 +260,6 @@ public IpPacket()
/// </returns>
internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment payload,
IPProtocolType ProtocolType,
- PosixTimeval Timeval,
Packet ParentPacket)
{
log.DebugFormat("payload: {0}, ParentPacket.GetType() {1}",
View
3  PacketDotNet/LinuxSLLPacket.cs
@@ -159,8 +159,7 @@ public LinuxSLLPacket(ByteArraySegment bas)
// parse the payload via an EthernetPacket method
payloadPacketOrData = EthernetPacket.ParseEncapsulatedBytes(header,
- EthernetProtocolType,
- Timeval);
+ EthernetProtocolType);
}
/// <summary cref="Packet.ToString(StringOutputType)" />
View
3  PacketDotNet/PPPPacket.cs
@@ -94,11 +94,10 @@ public PPPPacket(ByteArraySegment bas)
header.Length = PPPFields.HeaderLength;
// parse the encapsulated bytes
- payloadPacketOrData = ParseEncapsulatedBytes(header, Timeval, Protocol);
+ payloadPacketOrData = ParseEncapsulatedBytes(header, Protocol);
}
internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header,
- PosixTimeval Timeval,
PPPProtocol Protocol)
{
// slice off the payload
View
5 PacketDotNet/PPPoEPacket.cs
@@ -197,11 +197,10 @@ public PPPoEPacket(ByteArraySegment bas)
header.Length = PPPoEFields.HeaderLength;
// parse the encapsulated bytes
- payloadPacketOrData = ParseEncapsulatedBytes(header, Timeval);
+ payloadPacketOrData = ParseEncapsulatedBytes(header);
}
- internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header,
- PosixTimeval Timeval)
+ internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header)
{
// slice off the payload
var payload = Header.EncapsulatedBytes();
View
43 PacketDotNet/Packet.cs
@@ -48,17 +48,6 @@ public abstract class Packet
internal Packet parentPacket;
- internal PosixTimeval timeval;
-
- /// <value>
- /// PosixTimeval of this packet, can be the packet arrival time
- /// or the packet creation time
- /// </value>
- public virtual PosixTimeval Timeval
- {
- get { return timeval; }
- }
-
// recursively finds the length of this packet and all of the packets
// encapsulated by this packet
internal int TotalPacketLength
@@ -273,33 +262,6 @@ public virtual ByteArraySegment BytesHighPerformance
/// </summary>
public Packet()
{
- timeval = new PosixTimeval();
- }
-
- /// <summary>
- /// Turns an array of bytes into an EthernetPacket
- /// </summary>
- /// <param name="data">The packets caught</param>
- /// <returns>An ethernet packet which has references to the higher protocols</returns>
- public static Packet Parse(byte[] data)
- {
- return new EthernetPacket(new ByteArraySegment(data));
- }
-
- /// <summary>
- /// Parse a raw packet into its specific packets and payloads
- /// </summary>
- /// <param name="rawPacket">
- /// A <see cref="RawPacket"/>
- /// </param>
- /// <returns>
- /// A <see cref="Packet"/>
- /// </returns>
- public static Packet ParsePacket(RawPacket rawPacket)
- {
- return ParsePacket(rawPacket.LinkLayerType,
- rawPacket.Timeval,
- rawPacket.Data);
}
/// <summary>
@@ -308,9 +270,6 @@ public static Packet ParsePacket(RawPacket rawPacket)
/// <param name="LinkLayer">
/// A <see cref="LinkLayers"/>
/// </param>
- /// <param name="Timeval">
- /// A <see cref="PosixTimeval"/>
- /// </param>
/// <param name="PacketData">
/// A <see cref="System.Byte"/>
/// </param>
@@ -318,7 +277,6 @@ public static Packet ParsePacket(RawPacket rawPacket)
/// A <see cref="Packet"/>
/// </returns>
public static Packet ParsePacket(LinkLayers LinkLayer,
- PosixTimeval Timeval,
byte[] PacketData)
{
Packet p;
@@ -347,7 +305,6 @@ public static Packet ParsePacket(RawPacket rawPacket)
throw new System.NotImplementedException("LinkLayer of " + LinkLayer + " is not implemented");
}
- p.timeval = Timeval;
return p;
}
View
6 PacketDotNet/PacketDotNet.csproj
@@ -36,11 +36,11 @@
<GenerateDocumentation>true</GenerateDocumentation>
</PropertyGroup>
<ItemGroup>
- <Reference Include="System" />
- <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=a5715cc6d5c3540b" Condition=" '$(Configuration)' == 'DEBUG' ">
+ <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=a5715cc6d5c3540b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\log4net.dll</HintPath>
</Reference>
+ <Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
@@ -97,12 +97,10 @@
<Compile Include="IpVersion.cs" />
<Compile Include="LinkLayers.cs" />
<Compile Include="Utils\HexPrinter.cs" />
- <Compile Include="PosixTimeval.cs" />
<Compile Include="ILogInactive.cs" />
<Compile Include="Utils\RandomUtils.cs" />
<Compile Include="PayloadType.cs" />
<Compile Include="ICMPv6Types.cs" />
- <Compile Include="RawPacket.cs" />
<Compile Include="ARPOperation.cs" />
<Compile Include="PPPoEPacket.cs" />
<Compile Include="PPPoEFields.cs" />
View
13 PacketDotNet/PacketDotNet.csproj.user
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <PublishUrlHistory />
- <InstallUrlHistory />
- <SupportUrlHistory />
- <UpdateUrlHistory />
- <BootstrapperUrlHistory />
- <ErrorReportUrlHistory />
- <FallbackCulture>de-DE</FallbackCulture>
- <VerifyUploadedFiles>false</VerifyUploadedFiles>
- </PropertyGroup>
-</Project>
View
122 PacketDotNet/RawPacket.cs
@@ -1,122 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using PacketDotNet.Utils;
-
-namespace PacketDotNet
-{
- /// <summary>
- /// Raw packet as loaded from a pcap device or file
- /// </summary>
- public class RawPacket
- {
- /// <value>
- /// Link layer from which this packet was captured
- /// </value>
- public LinkLayers LinkLayerType
- {
- get;
- set;
- }
-
- /// <value>
- /// The unix timeval when the packet was created
- /// </value>
- public PosixTimeval Timeval
- {
- get;
- set;
- }
-
- /// <summary> Fetch data portion of the packet.</summary>
- public virtual byte[] Data
- {
- get;
- set;
- }
-
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="LinkLayerType">
- /// A <see cref="LinkLayers"/>
- /// </param>
- /// <param name="Timeval">
- /// A <see cref="PosixTimeval"/>
- /// </param>
- /// <param name="Data">
- /// A <see cref="System.Byte"/>
- /// </param>
- public RawPacket(LinkLayers LinkLayerType,
- PosixTimeval Timeval,
- byte[] Data)
- {
- this.LinkLayerType = LinkLayerType;
- this.Timeval = Timeval;
- this.Data = Data;
- }
-
- /// <value>
- /// Color used when generating the text description of a packet
- /// </value>
- public virtual System.String Color
- {
- get
- {
- return AnsiEscapeSequences.Black;
- }
- }
-
- /// <summary>Output this packet as a readable string</summary>
- public override System.String ToString()
- {
- return ToString(StringOutputType.Normal);
- }
-
- /// <summary cref="Packet.ToString(StringOutputType)" />
- public string ToString(StringOutputType outputFormat)
- {
- var buffer = new StringBuilder();
- string color = "";
- string colorEscape = "";
-
- if(outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
- {
- color = Color;
- colorEscape = AnsiEscapeSequences.Reset;
- }
-
- if(outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
- {
- // build the output string
- buffer.AppendFormat("[{0}RawPacket: LinkLayerType={2}, Timeval={3}]{1}",
- color,
- colorEscape,
- LinkLayerType,
- Timeval);
- }
-
- if(outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
- {
- // collect the properties and their value
- Dictionary<string,string> properties = new Dictionary<string,string>();
- properties.Add("link layer type", LinkLayerType.ToString() + " (0x" + LinkLayerType.ToString("x") + ")");
- properties.Add("timeval", Timeval.ToString());
-
- // calculate the padding needed to right-justify the property names
- int padLength = Utils.RandomUtils.LongestStringLength(new List<string>(properties.Keys));
-
- // build the output string
- buffer.AppendLine("Raw: ******* Raw - \"Raw Packet\"");
- buffer.AppendLine("Raw:");
- foreach(var property in properties)
- {
- buffer.AppendLine("Raw: " + property.Key.PadLeft(padLength) + " = " + property.Value);
- }
- buffer.AppendLine("Raw:");
- }
-
- return buffer.ToString();
- }
- }
-}
View
10 PacketDotNet/TransportProtocols.cs
@@ -1,10 +0,0 @@
-namespace PacketDotNet
-{
-#if false
- public enum TransportProtocols : ushort
- {
- Tcp = 6,
- Udp = 17
- };
-#endif
-}
View
2  SharpPcap/ARP.cs
@@ -224,7 +224,7 @@ public PhysicalAddress Resolve(System.Net.IPAddress destIP, string deviceName)
}
// parse the packet
- var packet = PacketDotNet.Packet.ParsePacket(reply);
+ var packet = PacketDotNet.Packet.ParsePacket(reply.LinkLayerType, reply.Data);
// is this an arp packet?
arpPacket = PacketDotNet.ARPPacket.GetEncapsulated(packet);
View
18 SharpPcap/AirPcap/AirPcapDevice.cs
@@ -685,7 +685,7 @@ public override PacketDotNet.LinkLayers LinkType
/// <summary>
/// Mac address
/// </summary>
- public PhysicalAddress MacAddress
+ public override PhysicalAddress MacAddress
{
get
{
@@ -885,7 +885,7 @@ protected override void CaptureThread()
UInt32 BytesReceived;
- List<PacketDotNet.RawPacket> packets;
+ List<RawCapture> packets;
while (!shouldCaptureThreadStop)
{
@@ -924,13 +924,13 @@ protected override void CaptureThread()
/// <param name="bufferEnd"></param>
/// <param name="packets"></param>
protected virtual void MarshalPackets(IntPtr packetsBuffer, IntPtr bufferEnd,
- out List<PacketDotNet.RawPacket> packets)
+ out List<RawCapture> packets)
{
- PacketDotNet.RawPacket p;
+ RawCapture p;
var linkType = LinkType;
- packets = new List<PacketDotNet.RawPacket>();
+ packets = new List<RawCapture>();
IntPtr bufferPointer = packetsBuffer;
@@ -945,10 +945,10 @@ protected override void CaptureThread()
var pkt_data = new byte[header.Caplen];
Marshal.Copy(bufferPointer, pkt_data, 0, (int)header.Caplen);
- p = new PacketDotNet.RawPacket(linkType,
- new PacketDotNet.PosixTimeval(header.TsSec,
- header.TsUsec),
- pkt_data);
+ p = new RawCapture(linkType,
+ new PosixTimeval(header.TsSec,
+ header.TsUsec),
+ pkt_data);
packets.Add(p);
View
2  SharpPcap/AssemblyInfo.cs
@@ -25,7 +25,7 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("3.5.0")]
+[assembly: AssemblyVersion("3.6.0")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
View
8 SharpPcap/CaptureEventArgs.cs
@@ -28,12 +28,12 @@ namespace SharpPcap
/// </summary>
public class CaptureEventArgs : EventArgs
{
- private PacketDotNet.RawPacket packet;
+ private RawCapture packet;
/// <summary>
/// Packet that was captured
/// </summary>
- public PacketDotNet.RawPacket Packet
+ public RawCapture Packet
{
get { return packet; }
}
@@ -52,12 +52,12 @@ public ICaptureDevice Device
/// Constructor
/// </summary>
/// <param name="packet">
- /// A <see cref="PacketDotNet.RawPacket"/>
+ /// A <see cref="RawCapture"/>
/// </param>
/// <param name="device">
/// A <see cref="ICaptureDevice"/>
/// </param>
- public CaptureEventArgs(PacketDotNet.RawPacket packet, ICaptureDevice device)
+ public CaptureEventArgs(RawCapture packet, ICaptureDevice device)
{
this.packet = packet;
this.device = device;
View
42 SharpPcap/CaptureMode.cs
@@ -1,42 +0,0 @@
-/*
-This file is part of SharpPcap.
-
-SharpPcap is free software: you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-SharpPcap is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License
-along with SharpPcap. If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
- */
-
-using System;
-
-namespace SharpPcap
-{
- /// <summary>
- /// The working mode of a Pcap device
- /// </summary>
- public enum CaptureMode : int
- {
- /// <summary>
- /// Set a Pcap device to capture packets, Capture mode
- /// </summary>
- Packets = 0,
-
- /// <summary>
- /// Set a Pcap device to report statistics.
- /// <br/>
- /// Statistics mode is only supported in WinPcap
- /// </summary>
- Statistics = 1
- };
-}
View
9 SharpPcap/ICaptureDevice.cs
@@ -53,6 +53,11 @@ public interface ICaptureDevice
/// </summary>
ICaptureStatistics Statistics { get; }
+ /// <summary>
+ /// Mac address of the physical device
+ /// </summary>
+ System.Net.NetworkInformation.PhysicalAddress MacAddress { get; }
+
#region Dump related
/// <summary>
/// Gets a value indicating whether a dump file is already associated with this device
@@ -63,7 +68,7 @@ public interface ICaptureDevice
/// Writes a packet to the pcap dump file associated with this device.
/// </summary>
/// <param name="p">The packet to write</param>
- void Dump(PacketDotNet.RawPacket p);
+ void Dump(RawCapture p);
/// <summary>
/// Opens a file for packet writings
@@ -156,7 +161,7 @@ public interface ICaptureDevice
/// Retrieves the next packet from a device
/// </summary>
/// <returns></returns>
- PacketDotNet.RawPacket GetNextPacket();
+ RawCapture GetNextPacket();
/// <summary>
/// Sends a raw packet throgh this device
View
20 SharpPcap/LibPcap/LibPcapLiveDevice.cs
@@ -41,6 +41,26 @@ public class LibPcapLiveDevice : PcapDevice
internal LibPcapLiveDevice( PcapInterface pcapIf )
{
m_pcapIf = pcapIf;
+
+ // go through the network interfaces and attempt to populate the mac address,
+ // friendly name etc of this device
+ NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
+ foreach (NetworkInterface adapter in nics)
+ {
+ // if the name and id match then we have found the NetworkInterface
+ // that matches the PcapDevice
+ if (Name.EndsWith(adapter.Id))
+ {
+ var ipProperties = adapter.GetIPProperties();
+ if (ipProperties.GatewayAddresses.Count != 0)
+ {
+ Interface.GatewayAddress = ipProperties.GatewayAddresses[0].Address;
+ }
+
+ Interface.MacAddress = adapter.GetPhysicalAddress();
+ Interface.FriendlyName = adapter.Name;
+ }
+ }
}
/// <summary>
View
23 SharpPcap/LibPcap/LibPcapLiveDeviceList.cs
@@ -104,29 +104,6 @@ private static List<LibPcapLiveDevice> GetDevices()
}
LibPcapSafeNativeMethods.pcap_freealldevs(devicePtr); // Free unmanaged memory allocation.
- // go through the network interfaces to populate the mac address
- // for each of the devices
- NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
- foreach(LibPcapLiveDevice device in deviceList)
- {
- foreach(NetworkInterface adapter in nics)
- {
- // if the name and id match then we have found the NetworkInterface
- // that matches the PcapDevice
- if(device.Name.EndsWith(adapter.Id))
- {
- var ipProperties = adapter.GetIPProperties();
- if (ipProperties.GatewayAddresses.Count != 0)
- {
- device.Interface.GatewayAddress = ipProperties.GatewayAddresses[0].Address;
- }
-
- device.Interface.MacAddress = adapter.GetPhysicalAddress();
- device.Interface.FriendlyName = adapter.Name;
- }
- }
- }
-
return deviceList;
}
View
60 SharpPcap/LibPcap/PcapDevice.cs
@@ -68,6 +68,22 @@ public abstract partial class PcapDevice : ICaptureDevice
public event PacketArrivalEventHandler OnPacketArrival;
/// <summary>
+ /// Implemented because there isn't any way to perform
+ /// if(OnPacketArrival == null) isn't permitted outside of the containing class
+ /// this operation results in a CS0070 compile error
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.Boolean"/>
+ /// </returns>
+ internal bool IsOnPacketArrivalNull
+ {
+ get
+ {
+ return (OnPacketArrival == null);
+ }
+ }
+
+ /// <summary>
/// Fired when the capture process of this pcap device is stopped
/// </summary>
public event CaptureStoppedEventHandler OnCaptureStopped;
@@ -204,12 +220,30 @@ public virtual void Close()
public abstract ICaptureStatistics Statistics { get; }
/// <summary>
+ /// Mac address of the physical device
+ /// </summary>
+ public virtual System.Net.NetworkInformation.PhysicalAddress MacAddress
+ {
+ get
+ {
+ ThrowIfNotOpen("device not open");
+
+ return Interface.MacAddress;
+ }
+
+ set
+ {
+ throw new System.NotImplementedException();
+ }
+ }
+
+ /// <summary>
/// Notify the OnPacketArrival delegates about a newly captured packet
/// </summary>
/// <param name="p">
- /// A <see cref="PacketDotNet.RawPacket"/>
+ /// A <see cref="RawCapture"/>
/// </param>
- protected void SendPacketArrivalEvent(PacketDotNet.RawPacket p)
+ protected void SendPacketArrivalEvent(RawCapture p)
{
var handler = OnPacketArrival;
if(handler != null )
@@ -238,9 +272,9 @@ protected void SendCaptureStoppedEvent(CaptureStoppedEventStatus status)
/// Gets the next packet captured on this device
/// </summary>
/// <returns>The next packet captured on this device</returns>
- public virtual PacketDotNet.RawPacket GetNextPacket()
+ public virtual RawCapture GetNextPacket()
{
- PacketDotNet.RawPacket p;
+ RawCapture p;
int res = GetNextPacket( out p );
if(res==-1)
throw new PcapException("Error receiving packet.");
@@ -251,12 +285,12 @@ public virtual PacketDotNet.RawPacket GetNextPacket()
/// Gets the next packet captured on this device
/// </summary>
/// <param name="p">
- /// A <see cref="PacketDotNet.RawPacket"/>
+ /// A <see cref="RawCapture"/>
/// </param>
/// <returns>
/// A <see cref="System.Int32"/> that contains the result code
/// </returns>
- public virtual int GetNextPacket(out PacketDotNet.RawPacket p)
+ public virtual int GetNextPacket(out RawCapture p)
{
//Pointer to a packet info struct
IntPtr header = IntPtr.Zero;
@@ -314,11 +348,11 @@ protected virtual void PacketHandler(IntPtr param, IntPtr /* pcap_pkthdr* */ hea
/// A <see cref="IntPtr"/>
/// </param>
/// <returns>
- /// A <see cref="PacketDotNet.RawPacket"/>
+ /// A <see cref="RawCapture"/>
/// </returns>
- protected virtual PacketDotNet.RawPacket MarshalRawPacket(IntPtr /* pcap_pkthdr* */ header, IntPtr data)
+ protected virtual RawCapture MarshalRawPacket(IntPtr /* pcap_pkthdr* */ header, IntPtr data)
{
- PacketDotNet.RawPacket p;
+ RawCapture p;
// marshal the header
var pcapHeader = new PcapHeader(header);
@@ -326,9 +360,9 @@ protected virtual PacketDotNet.RawPacket MarshalRawPacket(IntPtr /* pcap_pkthdr*
var pkt_data = new byte[pcapHeader.CaptureLength];
Marshal.Copy(data, pkt_data, 0, (int)pcapHeader.CaptureLength);
- p = new PacketDotNet.RawPacket(LinkType,
- new PacketDotNet.PosixTimeval(pcapHeader.Seconds,
- pcapHeader.MicroSeconds),
+ p = new RawCapture(LinkType,
+ new PosixTimeval(pcapHeader.Seconds,
+ pcapHeader.MicroSeconds),
pkt_data);
return p;
@@ -413,7 +447,7 @@ public void Dump(byte[] p)
/// Writes a packet to the pcap dump file associated with this device.
/// </summary>
/// <param name="p">The packet to write</param>
- public void Dump(PacketDotNet.RawPacket p)
+ public void Dump(RawCapture p)
{
var data = p.Data;
var timeval = p.Timeval;
View
330 SharpPcap/LivePcapDevice.cs
@@ -1,330 +0,0 @@
-/*
-This file is part of SharpPcap.
-
-SharpPcap is free software: you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-SharpPcap is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License
-along with SharpPcap. If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- * Copyright 2005 Tamir Gal <tamir@tamirgal.com>
- * Copyright 2008-2009 Chris Morgan <chmorgan@gmail.com>
- * Copyright 2008-2010 Phillip Lemon <lucidcomms@gmail.com>
- */
-
-using System;
-using System.Text;
-using System.Collections.ObjectModel;
-using System.Net.NetworkInformation;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-
-namespace SharpPcap
-{
- /// <summary>
- /// Capture live packets from a network device
- /// </summary>
- public class LivePcapDevice : PcapDevice
- {
- /// <summary>
- /// Constructs a new PcapDevice based on a 'pcapIf' struct
- /// </summary>
- /// <param name="pcapIf">A 'pcapIf' struct representing
- /// the pcap device</param>
- internal LivePcapDevice( PcapInterface pcapIf )
- {
- m_pcapIf = pcapIf;
- }
-
- /// <summary>
- /// Default contructor for subclasses
- /// </summary>
- protected LivePcapDevice()
- {
- }
-
- /// <summary>
- /// PcapDevice finalizer. Ensure PcapDevices are stopped and closed before exit.
- /// </summary>
- ~LivePcapDevice()
- {
- this.Close();
- }
-
- /// <summary>
- /// Gets the pcap name of this network device
- /// </summary>
- public override string Name
- {
- get { return m_pcapIf.Name; }
- }
-
- /// <summary>
- /// Addresses that represent this device
- /// </summary>
- public virtual ReadOnlyCollection<PcapAddress> Addresses
- {
- get { return new ReadOnlyCollection<PcapAddress>(m_pcapIf.Addresses); }
- }
-
- /// <summary>
- /// Gets the pcap description of this device
- /// </summary>
- public override string Description
- {
- get { return m_pcapIf.Description; }
- }
-
- /// <summary>
- /// Interface flags, see pcap_findalldevs() man page for more info
- /// </summary>
- public virtual uint Flags
- {
- get { return m_pcapIf.Flags; }
- }
-
- /// <summary>
- /// True if device is a loopback interface, false if not
- /// </summary>
- public virtual bool Loopback
- {
- get { return (Flags & Pcap.PCAP_IF_LOOPBACK)==1; }
- }
-
- /// <summary>
- /// Open the device with default values of: promiscuous_mode = false, read_timeout = 1000
- /// To start capturing call the 'StartCapture' function
- /// </summary>
- public override void Open()
- {
- this.Open(DeviceMode.Normal);
- }
-
- /// <summary>
- /// Open the device. To start capturing call the 'StartCapture' function
- /// </summary>
- /// <param name="mode">
- /// A <see cref="DeviceMode"/>
- /// </param>
- public virtual void Open(DeviceMode mode)
- {
- const int readTimeoutMilliseconds = 1000;
- this.Open(mode, readTimeoutMilliseconds);
- }
-
- /// <summary>
- /// Open the device. To start capturing call the 'StartCapture' function
- /// </summary>
- /// <param name="mode">
- /// A <see cref="DeviceMode"/>
- /// </param>
- /// <param name="read_timeout">
- /// A <see cref="System.Int32"/>
- /// </param>
- public virtual void Open(DeviceMode mode, int read_timeout)
- {
- if ( !Opened )
- {
- StringBuilder errbuf = new StringBuilder( Pcap.PCAP_ERRBUF_SIZE ); //will hold errors
-
- PcapHandle = SafeNativeMethods.pcap_open_live
- ( Name, // name of the device
- Pcap.MAX_PACKET_SIZE, // portion of the packet to capture.
- // MAX_PACKET_SIZE (65536) grants that the whole packet will be captured on all the MACs.
- (short)mode, // promiscuous mode
- (short)read_timeout, // read timeout
- errbuf ); // error buffer
-
- if ( PcapHandle == IntPtr.Zero)
- {
- string err = "Unable to open the adapter ("+Name+"). "+errbuf.ToString();
- throw new PcapException( err );
- }
- }
- }
-
- private const int disableBlocking = 0;
- private const int enableBlocking = 1;
-
- /// <summary>
- /// Set/Get Non-Blocking Mode. returns allways false for savefiles.
- /// </summary>
- public bool NonBlockingMode
- {
- get
- {
- var errbuf = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE); //will hold errors
- int ret = SafeNativeMethods.pcap_getnonblock(PcapHandle, errbuf);
-
- // Errorbuf is only filled when ret = -1
- if (ret == -1)
- {
- string err = "Unable to set get blocking" + errbuf.ToString();
- throw new PcapException(err);
- }
-
- if(ret == enableBlocking)
- return true;
- return false;
- }
- set
- {
- var errbuf = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE); //will hold errors
-
- int block = disableBlocking;
- if (value)
- block = enableBlocking;
-
- int ret = SafeNativeMethods.pcap_setnonblock(PcapHandle, block, errbuf);
-
- // Errorbuf is only filled when ret = -1
- if (ret == -1)
- {
- string err = "Unable to set non blocking" + errbuf.ToString();
- throw new PcapException(err);
- }
- }
- }
-
- /// <summary>
- /// Sends a raw packet throgh this device
- /// </summary>
- /// <param name="p">The packet to send</param>
- public void SendPacket(PacketDotNet.Packet p)
- {
- SendPacket(p.Bytes);
- }
-
-
- /// <summary>
- /// Sends a raw packet throgh this device
- /// </summary>
- /// <param name="p">The packet to send</param>
- /// <param name="size">The number of bytes to send</param>
- public void SendPacket(PacketDotNet.Packet p, int size)
- {
- SendPacket(p.Bytes, size);
- }
-
- /// <summary>
- /// Sends a raw packet throgh this device
- /// </summary>
- /// <param name="p">The packet bytes to send</param>
- public void SendPacket(byte[] p)
- {
- SendPacket(p, p.Length);
- }
-
- /// <summary>
- /// Sends a raw packet throgh this device
- /// </summary>
- /// <param name="p">The packet bytes to send</param>
- /// <param name="size">The number of bytes to send</param>
- public void SendPacket(byte[] p, int size)
- {
-
- ThrowIfNotOpen("Can't send packet, the device is closed");
-
- if (size > p.Length)
- {
- throw new ArgumentException("Invalid packetSize value: "+size+
- "\nArgument size is larger than the total size of the packet.");
- }
-
- if (p.Length > Pcap.MAX_PACKET_SIZE)
- {
- throw new ArgumentException("Packet length can't be larger than "+Pcap.MAX_PACKET_SIZE);
- }
-
- IntPtr p_packet = IntPtr.Zero;
- p_packet = Marshal.AllocHGlobal( size );
- Marshal.Copy(p, 0, p_packet, size);
-
- int res = SafeNativeMethods.pcap_sendpacket(PcapHandle, p_packet, size);
- Marshal.FreeHGlobal(p_packet);
- if(res < 0)
- {
- throw new PcapException("Can't send packet: " + LastError);
- }
- }
-
- /// <summary>
- /// Sends all packets in a 'PcapSendQueue' out this pcap device
- /// </summary>
- /// <param name="q">
- /// A <see cref="SendQueue"/>
- /// </param>
- /// <param name="transmitMode">
- /// A <see cref="SendQueueTransmitModes"/>
- /// </param>
- /// <returns>
- /// A <see cref="System.Int32"/>
- /// </returns>
- public int SendQueue( SendQueue q, SendQueueTransmitModes transmitMode )
- {
- return q.Transmit( this, transmitMode);
- }
-
- /// <summary>
- /// Retrieves pcap statistics
- /// </summary>
- /// <returns>
- /// A <see cref="PcapStatistics"/>
- /// </returns>
- public override PcapStatistics Statistics()
- {
- // can only call PcapStatistics on an open device
- ThrowIfNotOpen("device not open");
-
- return new PcapStatistics(this.m_pcapAdapterHandle);
- }
-
- /// <value>
- /// Set the kernel value buffer size in bytes
- /// WinPcap extension
- /// </value>
- public int KernelBufferSize
- {
- set
- {
- ThrowIfNotWinPcap();
- ThrowIfNotOpen("Can't set kernel buffer size, the device is not opened");
-
- int retval = SafeNativeMethods.pcap_setbuff(this.m_pcapAdapterHandle,
- value);
- if(retval != 0)
- {
- throw new System.InvalidOperationException("pcap_setbuff() failed");
- }
- }
- }
-
- /// <value>
- /// Set the MinToCopy value in bytes
- /// WinPcap extension
- /// </value>
- public int MinToCopy
- {
- set
- {
- ThrowIfNotWinPcap();
- ThrowIfNotOpen("Can't set MinToCopy size, the device is not opened");
-
- int retval = SafeNativeMethods.pcap_setmintocopy(this.m_pcapAdapterHandle,
- value);
- if (retval != 0)
- {
- throw new System.InvalidOperationException("pcap_setbuff() failed");
- }
- }
- }
- }
-}
View
232 SharpPcap/LivePcapDeviceList.cs
@@ -1,232 +0,0 @@
-/*
-This file is part of SharpPcap.
-
-SharpPcap is free software: you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-SharpPcap is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License
-along with SharpPcap. If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- * Copyright 2005 Tamir Gal <tamir@tamirgal.com>
- * Copyright 2008-2009 Chris Morgan <chmorgan@gmail.com>
- */
-
-using System;
-using System.Text;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Net.NetworkInformation;
-using System.Runtime.InteropServices;
-
-namespace SharpPcap
-{
- /// <summary>
- /// List of available Pcap Interfaces.
- /// </summary>
- public class LivePcapDeviceList : ReadOnlyCollection<LivePcapDevice>
- {
- private static LivePcapDeviceList instance;
-
- /// <summary>
- /// Method to retrieve this classes singleton instance
- /// </summary>
- public static LivePcapDeviceList Instance
- {
- get
- {
- if(instance == null)
- {
- instance = new LivePcapDeviceList();
- }
-
- return instance;
- }
- }
-
- /// <summary>
- /// Caution: Use the singlton instance unless you know why you need to call this.
- /// One use is for multiple filters on the same physical device. To apply multiple
- /// filters open the same physical device multiple times, one for each
- /// filter by calling this routine and picking the same device out of each list.
- /// </summary>
- /// <returns>
- /// A <see cref="LivePcapDeviceList"/>
- /// </returns>
- public static LivePcapDeviceList New()
- {
- return new LivePcapDeviceList();
- }
-
- /// <summary>
- /// Represents a strongly typed, read-only list of PcapDevices.
- /// </summary>
- private LivePcapDeviceList() : base(new List<LivePcapDevice>())
- {
- Refresh();
- }
-
- /// <summary>
- /// Retrieve a list of the current PcapDevices
- /// </summary>
- /// <returns>
- /// A <see cref="List&lt;LivePcapDevice&gt;"/>
- /// </returns>
- private static List<LivePcapDevice> GetDevices()
- {
- var deviceList = new List<LivePcapDevice>();
-
- var devicePtr = IntPtr.Zero;
- var errorBuffer = new StringBuilder(256);
-
- int result = SafeNativeMethods.pcap_findalldevs(ref devicePtr, errorBuffer);
- if (result < 0)
- throw new PcapException(errorBuffer.ToString());
-
- IntPtr nextDevPtr = devicePtr;
-
- while (nextDevPtr != IntPtr.Zero)
- {
- // Marshal pointer into a struct
- PcapUnmanagedStructures.pcap_if pcap_if_unmanaged =
- (PcapUnmanagedStructures.pcap_if)Marshal.PtrToStructure(nextDevPtr,
- typeof(PcapUnmanagedStructures.pcap_if));
- PcapInterface pcap_if = new PcapInterface(pcap_if_unmanaged);
- deviceList.Add(new LivePcapDevice(pcap_if));
- nextDevPtr = pcap_if_unmanaged.Next;
- }
- SafeNativeMethods.pcap_freealldevs(devicePtr); // Free unmanaged memory allocation.
-
- // go through the network interfaces to populate the mac address
- // for each of the devices
- NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
- foreach(LivePcapDevice device in deviceList)
- {
- foreach(NetworkInterface adapter in nics)
- {
- // if the name and id match then we have found the NetworkInterface
- // that matches the PcapDevice
- if(device.Name.EndsWith(adapter.Id))
- {
- var ipProperties = adapter.GetIPProperties();
- if (ipProperties.GatewayAddresses.Count != 0)
- {
- device.Interface.GatewayAddress = ipProperties.GatewayAddresses[0].Address;
- }
-
- device.Interface.MacAddress = adapter.GetPhysicalAddress();
- device.Interface.FriendlyName = adapter.Name;
- }
- }
- }
-
- return deviceList;
- }
-
- /// <summary>
- /// Refresh the device list
- /// </summary>
- public void Refresh()
- {
- lock(this)
- {
- // retrieve the current device list
- var newDeviceList = GetDevices();
-
- // update existing devices with values in the new list
- foreach(var newItem in newDeviceList)
- {
- foreach(var existingItem in base.Items)
- {
- if(newItem.Name == existingItem.Name)
- {
- // copy the flags and addresses over
- existingItem.Interface.Flags = newItem.Interface.Flags;
- existingItem.Interface.Addresses = newItem.Interface.Addresses;
-
- break; // break out of the foreach(existingItem)
- }
- }
- }
-
- // find items the current list is missing
- foreach(var newItem in newDeviceList)
- {
- bool found = false;
- foreach(var existingItem in base.Items)
- {
- if(existingItem.Name == newItem.Name)
- {
- found = true;
- break;
- }
- }
-
- // add items that we were missing
- if(!found)
- {
- base.Items.Add(newItem);
- }
- }
-
- // find items that we have that the current list is missing
- var itemsToRemove = new List<LivePcapDevice>();
- foreach(var existingItem in base.Items)
- {
- bool found = false;
-
- foreach(var newItem in newDeviceList)
- {
- if(existingItem.Name == newItem.Name)
- {
- found = true;
- break;
- }
- }
-
- // add the PcapDevice we didn't see in the new list
- if(!found)
- {
- itemsToRemove.Add(existingItem);
- }
- }
-
- // remove the items outside of the foreach() to avoid
- // enumeration errors
- foreach(var itemToRemove in itemsToRemove)
- {
- base.Items.Remove(itemToRemove);
- }
- }
- }
-
- #region PcapDevice Indexers
- /// <param name="Name">The name or description of the pcap interface to get.</param>
- public LivePcapDevice this[string Name]
- {
- get
- {
- // lock to prevent issues with multi-threaded access
- // with other methods
- lock(this)
- {
- var devices = (List<LivePcapDevice>)base.Items;
- var dev = devices.Find(delegate(LivePcapDevice i) { return i.Name == Name; });
- var result = dev ?? devices.Find(delegate(LivePcapDevice i) { return i.Description == Name; });
-
- if (result == null)
- throw new IndexOutOfRangeException();
- return result;
- }
- }
- }
- #endregion
- }
-}
View
125 SharpPcap/OfflinePcapDevice.cs
@@ -1,125 +0,0 @@
-/*
-This file is part of SharpPcap.
-
-SharpPcap is free software: you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-SharpPcap is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License
-along with SharpPcap. If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- * Copyright 2005 Tamir Gal <tamir@tamirgal.com>
- * Copyright 2008-2009 Chris Morgan <chmorgan@gmail.com>
- * Copyright 2008-2009 Phillip Lemon <lucidcomms@gmail.com>
- */
-
-using System;
-using System.IO;
-using System.Text;
-
-namespace SharpPcap
-{
- /// <summary>
- /// Capture packets from an offline pcap file
- /// </summary>
- public class OfflinePcapDevice : PcapDevice
- {
- private string m_pcapFile;
-
- /// <summary>
- /// The description of this device
- /// </summary>
- private const string PCAP_OFFLINE_DESCRIPTION
- = "Offline pcap file";
-
- /// <summary>
- /// Constructs a new offline device for reading
- /// pcap files
- /// </summary>
- /// <param name="pcapFile"></param>
- public OfflinePcapDevice(string pcapFile)
- {
- m_pcapFile = pcapFile;
- }
-
- /// <value>
- /// The name of the capture file
- /// </value>
- public override string Name
- {
- get
- {
- return m_pcapFile;
- }
- }
-
- /// <value>
- /// Description of the device
- /// </value>
- public override string Description
- {
- get
- {
- return PCAP_OFFLINE_DESCRIPTION;
- }
- }
-
- /// <value>
- /// Number of bytes in the capture file
- /// </value>
- public long FileSize
- {
- get
- {
- return new FileInfo( Name ).Length;
- }
- }
-
- /// <summary>
- /// The underlying pcap file name
- /// </summary>
- public string FileName
- {
- get { return System.IO.Path.GetFileName( this.Name ); }
- }
-
- /// <summary>
- /// Opens the device for capture
- /// </summary>
- public override void Open()
- {
- // holds errors
- StringBuilder errbuf = new StringBuilder( Pcap.PCAP_ERRBUF_SIZE ); //will hold errors
- // opens offline pcap file
- IntPtr adapterHandle = SafeNativeMethods.pcap_open_offline( this.Name, errbuf);
-
- // handle error
- if ( adapterHandle == IntPtr.Zero)
- {
- string err = "Unable to open offline adapter: " + errbuf.ToString();
- throw new PcapException( err );
- }
-
- // set the local handle
- this.PcapHandle = adapterHandle;
- }
-
- /// <summary>
- /// Retrieves pcap statistics
- /// </summary>
- /// <returns>
- /// A <see cref="PcapStatistics"/>
- /// </returns>
- public override PcapStatistics Statistics()
- {
- throw new NotSupportedOnOfflineDeviceException("Statistics not supported on offline device");
- }
- }
-}
View
92 SharpPcap/PcapAddress.cs
@@ -1,92 +0,0 @@
-/*
-This file is part of SharpPcap.
-
-SharpPcap is free software: you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-SharpPcap is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License
-along with SharpPcap. If not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- * Copyright 2005 Tamir Gal <tamir@tamirgal.com>
- * Copyright 2009 Chris Morgan <chmorgan@gmail.com>
- */
-
-using System;
-using System.Text;
-
-namespace SharpPcap
-{
- /// <summary>
- /// Managed representation of the unmanaged pcap_addr structure
- /// </summary>
- public class PcapAddress
- {
- /// <summary>
- /// The address value of this PcapAddress, null if none is present
- /// </summary>
- public Sockaddr Addr { get; internal set; }
-
- /// <summary>
- /// Netmask of this PcapAddress, null if none is present
- /// </summary>
- public Sockaddr Netmask { get; internal set; }
-
- /// <summary>
- /// Broadcast address of this PcapAddress, null if none is present
- /// </summary>
- public Sockaddr Broadaddr { get; internal set; }
-
- /// <summary>
- /// Destination address, null if the interface isn't a point-to-point interface
- /// </summary>
- public Sockaddr Dstaddr {get; internal set; }
-
- internal PcapAddress()
- { }
-
- internal PcapAddress(PcapUnmanagedStructures.pcap_addr pcap_addr)
- {
- if(pcap_addr.Addr != IntPtr.Zero)
- Addr = new Sockaddr( pcap_addr.Addr );
- if(pcap_addr.Netmask != IntPtr.Zero)
- Netmask = new Sockaddr( pcap_addr.Netmask );
- if(pcap_addr.Broadaddr !=IntPtr.Zero)
- Broadaddr = new Sockaddr( pcap_addr.Broadaddr );
- if(pcap_addr.Dstaddr != IntPtr.Zero)
- Dstaddr = new Sockaddr( pcap_addr.Dstaddr );
- }
-
- /// <summary>
- /// ToString override
- /// </summary>
- /// <returns>
- /// A <see cref="System.String"/>
- /// </returns>
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
-
- if(Addr != null)
- sb.AppendFormat("Addr: {0}\n", Addr.ToString());
-
- if(Netmask != null)
- sb.AppendFormat("Netmask: {0}\n", Netmask.ToString());
-
- if(Broadaddr != null)
- sb.AppendFormat("Broadaddr: {0}\n", Broadaddr.ToString());
-
- if(Dstaddr != null)
- sb.AppendFormat("Dstaddr: {0}\n", Dstaddr.ToString());
-
- return sb.ToString();
- }
- }
-}
View
622 SharpPcap/PcapDevice.cs
@@ -1,622 +0,0 @@
-/*
-This file is part of SharpPcap.
-
-SharpPcap is free software: you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-SharpPcap is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the