BACnet.Ethernet.EthernetPort._onPacketArrival C# (CSharp) Method

_onPacketArrival() private method

Called whenever a packet is captured on the capture device
private _onPacketArrival ( object sender, SharpPcap.CaptureEventArgs e ) : void
sender object The sender of the event
e SharpPcap.CaptureEventArgs The event args
return void
        private void _onPacketArrival(object sender, CaptureEventArgs e)
        {
            // don't process any packet too short to not be valid
            if (e.Packet.Data.Length < _minimumPacketLength)
                return;

            // don't process any packets sent by the local device
            if (_isOutboundPacket(e.Packet.Data))
                return;

            byte[] buffer = e.Packet.Data;
            int offset = 0;
            Mac destination, source;
            int length;
            byte dsap, ssap, control;

            destination = new Mac(buffer, offset, 6);
            offset += 6;
            source = new Mac(buffer, offset, 6);
            offset += 6;
            length = buffer.ReadUInt16(offset);
            offset += 2;

            dsap = buffer[offset++];
            ssap = buffer[offset++];
            control = buffer[offset++];

            // don't process non-BACnet packets
            if (dsap != 0x82 || ssap != 0x82 || control != 0x03)
                return;

            NetgramReceivedMessage message = new NetgramReceivedMessage(
                this.PortId,
                source,
                new BufferSegment(buffer, offset, buffer.Length));
            if (Session != null)
            {
                Session.QueueMessage(message);
            }
        }