Exemple #1
0
        public PcapChunkWriter(Stream stream, ProtocolType protocolType)
        {
            _encoder = new IPBuilder(protocolType);

            var sh = SectionHeader.CreateEmptyHeader();

            sh.LinkType             = LinkTypes.Raw;
            sh.MaximumCaptureLength = 0x40000;
            _pcap = new PcapWriter(stream, sh);
        }
Exemple #2
0
 public void Disable()
 {
     lock (this.sync)
     {
         this.IsEnabled = false;
         if (this.writer != null)
         {
             this.writer.Dispose();
         }
         this.writer = null;
     }
 }
Exemple #3
0
 public void Enable(Stream stream)
 {
     lock (this.sync)
     {
         if (this.IsEnabled)
         {
             this.Disable();
         }
         this.writer    = new PcapWriter(stream);
         this.IsEnabled = true;
     }
 }
Exemple #4
0
 internal void Write(ServerAsyncEventArgs e, bool incomingOutgoing)
 {
     try
     {
         PcapWriter pcapWriter = this.writer;
         if (pcapWriter != null)
         {
             pcapWriter.Write(e.Buffer, e.Offset, incomingOutgoing ? e.BytesTransferred : e.Count, this.Convert(e.LocalEndPoint.Protocol), incomingOutgoing ? e.RemoteEndPoint : e.LocalEndPoint, incomingOutgoing ? e.LocalEndPoint : e.RemoteEndPoint);
         }
     }
     catch (ObjectDisposedException)
     {
     }
 }
Exemple #5
0
 public void WriteComment(string comment)
 {
     try
     {
         PcapWriter pcapWriter = this.writer;
         if (pcapWriter != null)
         {
             pcapWriter.WriteComment(comment);
         }
     }
     catch (ObjectDisposedException)
     {
     }
 }
Exemple #6
0
 public void Flush()
 {
     try
     {
         PcapWriter pcapWriter = this.writer;
         if (pcapWriter != null)
         {
             pcapWriter.Flush();
         }
     }
     catch (ObjectDisposedException)
     {
     }
 }
Exemple #7
0
        public void Disable()
        {
            lock (sync)
            {
                IsEnabled = false;

                if (writer != null)
                {
                    writer.Dispose();
                }

                writer = null;
            }
        }
Exemple #8
0
        public void Enable(Stream stream)
        {
            lock (sync)
            {
                if (IsEnabled)
                {
                    Disable();
                }

                writer = new PcapWriter(stream);

                IsEnabled = true;
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            using (var writer = new PcapWriter(File.Create("test.pcap")))
            {
                //writer.Write("Hello W!", false);
                //writer.Write("Hello W!", true);

                writer.WriteComment("It is comment!");

                //var message = Encoding.UTF8.GetBytes("Hello World!");

                var message = Encoding.UTF8.GetBytes(
                    "REGISTER sip:officesip.local SIP/2.0\r\n" +
                    "Via: SIP/2.0/UDP 192.168.1.100:50554;rport;branch=z9hG4bKPjw.pkUaV7ZttbG6-bLQ8mkSpjLHXSbZ0z\r\n" +
                    "Route: <sip:192.168.1.15;lr>\r\n" +
                    "Max-Forwards: 70\r\n" +
                    "From: \"a\" <sip:[email protected]>;tag=8oiu15i7rANaIkeCgOo7VD.CqjuLy6ny\r\n" +
                    "To: \"a\" <sip:[email protected]>\r\n" +
                    "Call-ID: eCUdTyjBT3d5I0cLdL5EYr5QOMHHUVay\r\n" +
                    "CSeq: 7304 REGISTER\r\n" +
                    "User-Agent: CSipSimple r1099 / thunderg-10\r\n" +
                    "Contact: \"a\" <sip:[email protected]:50554;ob>\r\n" +
                    "Expires: 300\r\n" +
                    "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS\r\n" +
                    "Content-Length:  0\r\n" +
                    "\r\n");



                for (int i = 0; i < 1000; i++)
                {
                    writer.Write(message, Protocol.Udp, new IPEndPoint(IPAddress.Loopback, 1234), new IPEndPoint(IPAddress.Broadcast, 4321));
                    writer.Write(message, Protocol.Tcp, new IPEndPoint(IPAddress.Loopback, 1234), new IPEndPoint(IPAddress.Broadcast, 4321));
                    writer.Write(message, Protocol.Tls, new IPEndPoint(IPAddress.Loopback, 5678), new IPEndPoint(IPAddress.Broadcast, 8765));
                    writer.Write(message, Protocol.Udp, new IPEndPoint(IPAddress.IPv6Loopback, 1234), new IPEndPoint(IPAddress.IPv6Any, 4321));
                    writer.Write(message, Protocol.Tcp, new IPEndPoint(IPAddress.IPv6Loopback, 1234), new IPEndPoint(IPAddress.IPv6Any, 4321));
                    writer.Write(message, Protocol.Tls, new IPEndPoint(IPAddress.IPv6Loopback, 5678), new IPEndPoint(IPAddress.IPv6Any, 8765));
                }
            }
        }