private void redirector() { byte[] array = null; packet_headers packet_headers = null; this.isRedirecting = true; byte[] array2 = new byte[6]; byte[] array3 = new byte[4]; byte[] array4 = new byte[4]; PC router = this.pcList.getRouter(); if (router != null) { this.routerMAC = router.mac.GetAddressBytes(); } if (this.routerMAC == null) { MessageBox.Show("no router found to redirect packet"); this.isRedirecting = false; } else { if (this.isRedirecting) { do { if (this.pcapredirect.pcapnet_next_ex(out packet_headers, out array) != 0) { Array.Copy(array, 6, array2, 0, 6); if (tools.areValuesEqual(array2, this.localMAC)) { Array.Copy(array, 26, array3, 0, 4); if (tools.areValuesEqual(array3, this.localIP)) { this.pcList.getLocalPC().nbPacketSentSinceLastReset += (int)packet_headers.caplen; } } else if (tools.areValuesEqual(array2, this.routerMAC)) { Array.Copy(array, 30, array4, 0, 4); if (tools.areValuesEqual(array4, this.localIP)) { this.pcList.getLocalPC().nbPacketReceivedSinceLastReset += (int)packet_headers.caplen; } else { PC pcfromIP = this.pcList.getPCFromIP(array4); if (pcfromIP != null) { int capDown = pcfromIP.capDown; if ((capDown == 0 || capDown > pcfromIP.nbPacketReceivedSinceLastReset) && pcfromIP.redirect) { Array.Copy(pcfromIP.mac.GetAddressBytes(), 0, array, 0, 6); Array.Copy(this.localMAC, 0, array, 6, 6); this.pcapredirect.pcapnet_sendpacket(array); pcfromIP.nbPacketReceivedSinceLastReset += (int)packet_headers.caplen; } } } } else { Array.Copy(array, 30, array4, 0, 4); if (!tools.areValuesEqual(array4, this.localIP)) { PC pcfromMac = this.pcList.getPCFromMac(array2); if (pcfromMac != null) { int capUp = pcfromMac.capUp; if ((capUp == 0 || capUp > pcfromMac.nbPacketSentSinceLastReset) && pcfromMac.redirect) { Array.Copy(this.routerMAC, 0, array, 0, 6); Array.Copy(this.localMAC, 0, array, 6, 6); this.pcapredirect.pcapnet_sendpacket(array); pcfromMac.nbPacketSentSinceLastReset += (int)packet_headers.caplen; } } } } } } while (this.isRedirecting); } this.redirectorThreadTerminated.Set(); } }