Permalink
Browse files

updated SharpPcap to 3.6.0

  • Loading branch information...
1 parent 9cf405d commit 65498c113972c14078d9efd45da6baee2545f480 seuffert committed May 6, 2011
View
@@ -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);
@@ -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);
@@ -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
@@ -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;
@@ -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
- };
-}
@@ -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
@@ -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>
@@ -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;
}
@@ -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,21 +348,21 @@ 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);
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;
Oops, something went wrong.

0 comments on commit 65498c1

Please sign in to comment.