private void OnReceiveSink(IAsyncResult result) { byte[] buffer; IPEndPoint ep = null; object[] args = (object[])result.AsyncState; UdpClient session = (UdpClient)args[0]; IPEndPoint local = (IPEndPoint)args[1]; try { buffer = session.EndReceive(result, ref ep); try { HTTPMessage Packet = HTTPMessage.ParseByteArray(buffer, 0, buffer.Length); if (Packet != null) { Packet.LocalEndPoint = local; Packet.RemoteEndPoint = ep; ProcessPacket(Packet, Packet.RemoteEndPoint, local); } } catch (Exception ex) { OpenSource.Utilities.EventLogger.Log(ex); } session.BeginReceive(new AsyncCallback(OnReceiveSink), args); } catch (Exception ex) { OpenSource.Utilities.EventLogger.Log(ex); sessions.Remove(local.Address); } }
private void OnReceiveSink2(byte[] buffer, IPEndPoint remote, IPEndPoint local) { HTTPMessage msg; try { msg = HTTPMessage.ParseByteArray(buffer, 0, buffer.Length); } catch (Exception ex) { OpenSource.Utilities.EventLogger.Log(ex); msg = new HTTPMessage(); msg.Directive = "---"; msg.DirectiveObj = "---"; msg.BodyBuffer = buffer; } msg.LocalEndPoint = local; msg.RemoteEndPoint = remote; HandleSniffer(remote, local, msg); DText parser = new DText(); String Location = msg.GetTag("Location"); int MaxAge = 0; String ma = msg.GetTag("Cache-Control").Trim(); if (ma != "") { parser.ATTRMARK = ","; parser.MULTMARK = "="; parser[0] = ma; for (int i = 1; i <= parser.DCOUNT(); ++i) { if (parser[i, 1].Trim().ToUpper() == "MAX-AGE") { MaxAge = int.Parse(parser[i, 2].Trim()); break; } } } ma = msg.GetTag("USN"); String USN = ma.Substring(ma.IndexOf(":") + 1); String ST = msg.GetTag("ST"); if (USN.IndexOf("::") != -1) { USN = USN.Substring(0, USN.IndexOf("::")); } OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, msg.RemoteEndPoint.ToString()); if (OnSearch != null) { OnSearch(msg.RemoteEndPoint, msg.LocalEndPoint, new Uri(Location), USN, ST, MaxAge); } }