private void RaiseRTPArrived(RTPPacketEventArgs eventArgs) { if (this.RTPArrived != null) { RTPArrived(this, eventArgs); } }
/// <summary> /// Event handler called when a Pcap Packet has arrived /// </summary> /// <param name="sender">who raised it</param> /// <param name="packet">the packet</param> private void device_PcapOnPacketArrival(object sender, Packet packet) { string s; try { // not certain if this will be needed, but just for keep sake if (packet is TCPPacket) { /* * DateTime time = packet.PcapHeader.Date; * int len = packet.PcapHeader.PacketLength; * * TCPPacket tcp = (TCPPacket)packet; * string srcIp = tcp.SourceAddress; * string dstIp = tcp.DestinationAddress; * int srcPort = tcp.SourcePort; * int dstPort = tcp.estinationPort; * * Console.WriteLine( "{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}", * time.Hour, time.Minute, time.Second, time.Millisecond, len, * srcIp, srcPort, dstIp, dstPort ); */ } else if (packet is UDPPacket) { IPPacket p = packet as IPPacket; //if( p.DestinationAddress.Equals( ipAddress ) ) { DateTime time = packet.PcapHeader.Date; int len = packet.PcapHeader.PacketLength; UDPPacket udpPacket = (UDPPacket)packet; SipParser parser; if (packet.Data.Length > 0) { // TODO: Is there a better way here? s = System.Text.ASCIIEncoding.ASCII.GetString(packet.Data); if (s.Length > 0) { if (s.Contains("SIP")) { //DumpPacketToFiles( s ); //outs = String.Format( "{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}", // time.Hour, time.Minute, time.Second, time.Millisecond, len, // srcIp, srcPort, dstIp, dstPort ); //this.sw.WriteLine( outs ); //this.sw.Write( s ); //this.sw.Flush(); parser = new SipParser(s, ipAddress, udpPacket.DestinationAddress); //Console.WriteLine( // String.Format( "{0} {1} {2}", // parser.SipStatus, parser.SipStatusString, parser.ToField ) ); RaiseSipArrived(parser); packetCount++; } else { RTPPacketEventArgs eventArgs; eventArgs = new RTPPacketEventArgs(udpPacket.DestinationPort, udpPacket.Data); RaiseRTPArrived(eventArgs); } } } } } } catch (Exception ex) { ClsException.WriteToErrorLogFile(ex); } }
private void RaiseRTPArrived( RTPPacketEventArgs eventArgs ) { if( this.RTPArrived != null ) { RTPArrived( this, eventArgs ); } }
/// <summary> /// Event handler called when a Pcap Packet has arrived /// </summary> /// <param name="sender">who raised it</param> /// <param name="packet">the packet</param> private void device_PcapOnPacketArrival( object sender, Packet packet ) { string s; try { // not certain if this will be needed, but just for keep sake if( packet is TCPPacket ) { /* DateTime time = packet.PcapHeader.Date; int len = packet.PcapHeader.PacketLength; TCPPacket tcp = (TCPPacket)packet; string srcIp = tcp.SourceAddress; string dstIp = tcp.DestinationAddress; int srcPort = tcp.SourcePort; int dstPort = tcp.estinationPort; Console.WriteLine( "{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}", time.Hour, time.Minute, time.Second, time.Millisecond, len, srcIp, srcPort, dstIp, dstPort ); */ } else if( packet is UDPPacket ) { IPPacket p = packet as IPPacket; //if( p.DestinationAddress.Equals( ipAddress ) ) { DateTime time = packet.PcapHeader.Date; int len = packet.PcapHeader.PacketLength; UDPPacket udpPacket = (UDPPacket)packet; SipParser parser; if( packet.Data.Length > 0 ) { // TODO: Is there a better way here? s = System.Text.ASCIIEncoding.ASCII.GetString( packet.Data ); if( s.Length > 0 ) { if( s.Contains( "SIP" ) ) { //DumpPacketToFiles( s ); //outs = String.Format( "{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}", // time.Hour, time.Minute, time.Second, time.Millisecond, len, // srcIp, srcPort, dstIp, dstPort ); //this.sw.WriteLine( outs ); //this.sw.Write( s ); //this.sw.Flush(); parser = new SipParser( s, ipAddress, udpPacket.DestinationAddress ); //Console.WriteLine( // String.Format( "{0} {1} {2}", // parser.SipStatus, parser.SipStatusString, parser.ToField ) ); RaiseSipArrived( parser ); packetCount++; } else { RTPPacketEventArgs eventArgs; eventArgs = new RTPPacketEventArgs( udpPacket.DestinationPort, udpPacket.Data ); RaiseRTPArrived( eventArgs ); } } } } } } catch( Exception ex ) { ClsException.WriteToErrorLogFile( ex ); } }
/// <summary> /// Event handler for the RTP packets. /// </summary> /// <param name="sender">the packet sniffer in this case</param> /// <param name="eventArgs">contains the port number and RTP data stream.</param> private void OnRTPArrived( object sender, RTPPacketEventArgs eventArgs ) { ToneDetected toneDetected; // if we care about the port...process. if( RTPPort == eventArgs.Port ) { try { if( !someToneDetected ) { toneDetected = audioStreamState.AddPacket( eventArgs.Packet ); if( toneDetected != ToneDetected.NONE ) { someToneDetected = true; ClsException.WriteToLogFile( string.Format( "{0} Tone Detected: {1}", phoneNumber, toneDetected.ToString() ) ); RaiseNonHumanDetected( toneDetected ); } } } catch( Exception ex ) { ex.Data.Add( "My Key", "VMukti--:--VmuktiModules--:--VmuktiModules--:--Call Center--:--AutoProgressiveSoftPhone--:--AutoProgressivePhone.Business--:--RTCAudioWithToneDetect.cs--:--OnRTPArrived()--" ); ClsException.WriteToErrorLogFile( ex ); } } }