public void NicIsSelected(NetworkInterface nic) { this.pcs = new PcList(); this.pcs.SetCallBackOnNewPC(new delegateOnNewPC(this.callbackOnNewPC)); this.pcs.SetCallBackOnPCRemove(new delegateOnNewPC(this.callbackOnPCRemove)); this.nicNet = nic; CArp carp = new CArp(nic, this.pcs); this.cArp = carp; carp.startArpListener(); this.cArp.findMacRouter(); PC pc = new PC(); pc.ip = new IPAddress(this.cArp.localIP); pc.mac = new PhysicalAddress(this.cArp.localMAC); pc.capDown = 0; pc.capUp = 0; pc.isLocalPc = true; pc.name = string.Empty; pc.nbPacketReceivedSinceLastReset = 0; pc.nbPacketSentSinceLastReset = 0; pc.redirect = false; DateTime now = DateTime.Now; pc.timeSinceLastRarp = (ValueType)now; pc.totalPacketReceived = 0; pc.totalPacketSent = 0; pc.isGateway = false; this.pcs.addPcToList(pc); this.timer2.Interval = 5000; this.timer2.Start(); this.treeGridView1.Nodes[0].Expand(); }
public CArp(NetworkInterface nic, PcList pclist) { pcList = pclist; nicNet = nic; int num = 0; if (0 < nic.GetIPProperties().UnicastAddresses.Count) { do { if (!Convert.ToString(nicNet.GetIPProperties().UnicastAddresses[num].Address.AddressFamily).EndsWith("V6")) { localIP = nicNet.GetIPProperties().UnicastAddresses[num].Address.GetAddressBytes(); netmask = nicNet.GetIPProperties().UnicastAddresses[num].IPv4Mask.GetAddressBytes(); } num++; }while (num < nicNet.GetIPProperties().UnicastAddresses.Count); } localMAC = nicNet.GetPhysicalAddress().GetAddressBytes(); if (nicNet.GetIPProperties().GatewayAddresses.Count > 0) { routerIP = nicNet.GetIPProperties().GatewayAddresses[0].Address.GetAddressBytes(); } byte[] array = broadcastMac = new byte[6]; int num2 = 0; do { array[num2] = byte.MaxValue; num2++; }while (num2 < 6); pcaparp = new CPcapNet(); pcapredirect = new CPcapNet(); arpListenerThreadTerminated = new EventWaitHandle(initialState: false, EventResetMode.AutoReset); redirectorThreadTerminated = new EventWaitHandle(initialState: false, EventResetMode.AutoReset); discovererThreadTerminated = new EventWaitHandle(initialState: false, EventResetMode.AutoReset); isListeningArp = false; isDiscovering = false; isRedirecting = false; }