private void StartThread() { UdpClient receivingUdpClient = new UdpClient(PortServer); IPEndPoint RemoteIpEndPoint = null; try { while (!IsStop) { try { byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint); byte[] ip = RemoteIpEndPoint.Address.GetAddressBytes(); if (receiveBytes[1] != 0x05) { continue; } HeaderNetFlow header = this.ParsingHeder(ref receiveBytes); header.FromHost = (uint)(ip[3] & 0xFF | (ip[2] & 0xFF) << 8 | (ip[1] & 0xFF) << 16 | (ip[0] & 0xFF) << 24);//RawToUInt(ref ip, 0); RowNetFlow[] rows = new RowNetFlow[header.Count]; for (int i = 0; i < header.Count; i++) { rows[i] = this.ParsingRow(ref receiveBytes, 24 + i * 48); } if (uiContext != null) { uiContext.Post(OnNewPackage, new NewPackageEvent(receiveBytes) { Header = header, Rows = rows }); } else { OnNewPackage(new NewPackageEvent(receiveBytes) { Header = header, Rows = rows }); } } catch (ThreadAbortException exAbort) { Logs.Write(exAbort); } catch (Exception e) { Logs.Write(e); } } receivingUdpClient.Close(); } catch (Exception ex) { Logs.Write(ex); receivingUdpClient.Close(); } }
/// <summary> /// Парсинг заголовка пакета Netflow v5 /// </summary> /// param name="Data" ссылка не массив байт пакета private HeaderNetFlow ParsingHeder(ref byte[] Data) { HeaderNetFlow ret = new HeaderNetFlow(); ret.Version = 5; ret.Count = (ushort)((Data[3] & 0xFF) | (Data[2] & 0xFF) << 8); ret.Sys_uptime = RawToUInt(ref Data, 4); ret.Unix_secs = RawToUInt(ref Data, 8); ret.Unix_nsecs = RawToUInt(ref Data, 12); ret.Flow_sequence = RawToUInt(ref Data, 16); ret.Engine_type = Data[20]; ret.Engine_id = Data[21]; ret.Sampling_interval = (ushort)((Data[23] & 0xFF) | (Data[22] & 0xFF) << 8); return(ret); }