public void NicIsSelected(NetworkInterface nic) { pcs = new PcList(); pcs.SetCallBackOnNewPC(CallbackOnNewPC); pcs.SetCallBackOnPCRemove(callbackOnPCRemove); nicNet = nic; /* modopt(System.Runtime.CompilerServices.IsConst) */ CArp cArp = new CArp(nic, this.pcs); this.cArp = cArp; cArp.startArpListener(); this.cArp.findMacRouter(); PC pC = new PC() { ip = new IPAddress(this.cArp.localIP), mac = new PhysicalAddress(this.cArp.localMAC), CapDown = 0, CapUp = 0, isLocalPc = true, name = "", nbPacketReceivedSinceLastReset = 0, nbPacketSentSinceLastReset = 0, redirect = false, timeSinceLastRarp = DateTime.Now, totalPacketReceived = 0, totalPacketSent = 0, isGateway = false }; this.pcs.addPcToList(pC); this.timer2.Interval = 5000; this.timer2.Start(); this.treeGridView1.Nodes[0].Expand(); cArp.startArpDiscovery(); }
public CArp(NetworkInterface networkInterface, PcList pclist) { pcList = pclist; this.networkInterface = networkInterface; int num = 0; if (0 < networkInterface.GetIPProperties().UnicastAddresses.Count) { do { if (!Convert.ToString(this.networkInterface.GetIPProperties().UnicastAddresses[num].Address.AddressFamily).EndsWith("V6")) { CArp addressBytes = this; addressBytes.localIP = addressBytes.networkInterface.GetIPProperties().UnicastAddresses[num].Address.GetAddressBytes(); CArp cArp = this; cArp.netmask = cArp.networkInterface.GetIPProperties().UnicastAddresses[num].IPv4Mask.GetAddressBytes(); } num++; }while (num < this.networkInterface.GetIPProperties().UnicastAddresses.Count); } CArp addressBytes1 = this; addressBytes1.localMAC = addressBytes1.networkInterface.GetPhysicalAddress().GetAddressBytes(); if (this.networkInterface.GetIPProperties().GatewayAddresses.Count > 0) { CArp cArp1 = this; cArp1.routerIP = cArp1.networkInterface.GetIPProperties().GatewayAddresses[0].Address.GetAddressBytes(); } byte[] numArray = new byte[6]; broadcastMac = numArray; int num1 = 0; do { numArray[num1] = 255; num1++; }while (num1 < 6); pcaparp = new CPcapNet(); pcapredirect = new CPcapNet(); //arpListenerThreadTerminated = new EventWaitHandle(false, EventResetMode.AutoReset); //redirectorThreadTerminated = new EventWaitHandle(false, EventResetMode.AutoReset); //discovererThreadTerminated = new EventWaitHandle(false, EventResetMode.AutoReset); isListeningArp = false; isDiscovering = false; isRedirecting = false; }