/// <summary> /// Returns all interface extensions known by the Network Library Management Layer by default. This normally includes all Ethernet interfaces of the computer. /// </summary> /// <returns>All interface extensions known by the Network Library Management Layer by default</returns> public IInterfaceDefinition[] Create() { List <IInterfaceDefinition> lDefinitions = new List <IInterfaceDefinition>(); foreach (WinPcapInterface wpc in EthernetInterface.GetAllPcapInterfaces()) { if (InterfaceConfiguration.GetAdapterTypeForInterface(wpc.Name) == System.Net.NetworkInformation.NetworkInterfaceType.Ethernet || InterfaceConfiguration.GetAdapterTypeForInterface(wpc.Name) == System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211) { lDefinitions.Add(new EthernetInterfaceControlDefinition(wpc)); } } return(lDefinitions.ToArray()); }
/// <summary> /// Creates a new instance of this class, listening to the given interface /// </summary> /// <param name="wpcInterface">A WinPcapInterface which defines the interface to listen to</param> public EthernetInterface(WinPcapInterface wpcInterface) { if (InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet && InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.Ethernet3Megabit && InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx && InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.FastEthernetT && InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet && InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name) != System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211) { throw new ArgumentException("Only enabled ethernet interfaces are supported at the moment."); } if (wpcInterface.Name == null) { throw new ArgumentException("Cannot create an interface instance for an interface not properly recognised by WinPcap."); } bPromiscousMode = true; oInterfaceStartStopLock = new object(); AddressResolutionMethod = AddressResolution.NDP; bExcludeOwnTraffic = true; bExcludeLocalHostTraffic = true; arpHostTable = new HostTable(); lmacSpoofAdresses = new List <MACAddress>(); bRun = false; bShutdownPending = false; qFrameQueue = new Queue <byte[]>(); bIsRunning = false; areWorkToDo = new AutoResetEvent(false); this.wpcInterface = wpcInterface; wpcDevice = new WinPcapDotNet(); this.maMacAddress = InterfaceConfiguration.GetMacAddressForInterface(wpcInterface.Name); this.aType = InterfaceConfiguration.GetAdapterTypeForInterface(wpcInterface.Name); this.MTU = InterfaceConfiguration.GetMtuForInterface(wpcInterface.Name) - 18; //Reserve 18 bytes for our ethernet-header IPAddress[] arip = InterfaceConfiguration.GetIPAddressesForInterface(wpcInterface.Name); Subnetmask[] smMask = InterfaceConfiguration.GetIPSubnetsForInterface(wpcInterface.Name); for (int iC1 = 0; iC1 < arip.Length && iC1 < smMask.Length; iC1++) { this.AddAddress(arip[iC1], smMask[iC1]); } ipStandardgateways.AddRange(InterfaceConfiguration.GetIPStandardGatewaysForInterface(wpcInterface.Name)); this.strDNSName = Dns.GetHostName(); PrimaryMACAddress = this.MACAddress; }