コード例 #1
0
        public void HandleCapture(byte[] buffer, int offset, int length)
        {
            TimeSpan timeOffset = DateTime.UtcNow - _connectedAt;

            MemoryStream stream = PrepareSendFrame(RPCAP_VERSION, RPCAP_MSG_PACKET, 0);
            NetworkWriter writer = new NetworkWriter(stream);

            uint seconds = (uint)Math.Floor(timeOffset.TotalSeconds);
            uint microseconds = (uint)((timeOffset.Ticks % TimeSpan.TicksPerSecond) / 10L);

            int bytesToTransmit = Math.Min(_snapLength, length);

            writer.WriteUnsigned32(seconds);
            writer.WriteUnsigned32(microseconds);
            writer.WriteUnsigned32((uint)bytesToTransmit);
            writer.WriteUnsigned32((uint)length);
            writer.WriteUnsigned32(_packetNumber++);

            stream.Write(buffer, offset, bytesToTransmit);

            CompleteSendFrame(stream);
        }
コード例 #2
0
        void HandleStartCaptureRequest(byte[] data)
        {
            // Read in the various fields:
            NetworkReader reader = new NetworkReader(data);

            uint snapLength = reader.ReadUnsigned32();
            uint readTimeout = reader.ReadUnsigned32();
            ushort flags = reader.ReadUnsigned16();
            ushort clientDataPortOrZero = reader.ReadUnsigned16();

            ushort filterType = reader.ReadUnsigned16();
            ushort dummy = reader.ReadUnsigned16();
            uint numberOfItems = reader.ReadUnsigned32();

            for (int i = 0; i < numberOfItems; i++)
            {
                ushort code = reader.ReadUnsigned16();
                byte jumpTrue = reader.ReadUnsigned8();
                byte jumpFalse = reader.ReadUnsigned8();
                int instructionValue = reader.ReadSigned32();
            }

            // Set up a data port:
            if (_dataConnectorHandle == null)
            {
                _dataConnectorHandle = _service.Reactor.ListenStream(new RemoteCaptureProtocolDataFactory(this));
            }

            int bufferSize = (int)snapLength;
            ushort serverDataPort = (ushort)_dataConnectorHandle.ListeningOnPort;

            MemoryStream stream = PrepareSendFrame(RPCAP_VERSION, RPCAP_MSG_STARTCAP_REPLY, 0);
            NetworkWriter writer = new NetworkWriter(stream);

            writer.WriteSigned32(bufferSize);
            writer.WriteUnsigned16(serverDataPort);
            writer.WriteUnsigned16(0); // (This is a reserved field.)

            CompleteSendFrame(stream);
        }
コード例 #3
0
        void HandleOpenRequest(byte[] data)
        {
            string deviceName = Encoding.UTF8.GetString(data);

            MemoryStream stream = PrepareSendFrame(RPCAP_VERSION, RPCAP_MSG_OPEN_REPLY, 0);
            NetworkWriter writer = new NetworkWriter(stream);

            uint linkType = DLT_EN10MB;
            uint offsetFromUtc = 0;

            writer.WriteUnsigned32(linkType);
            writer.WriteUnsigned32(offsetFromUtc);

            CompleteSendFrame(stream);
        }