Exemplo n.º 1
0
        /// <summary>
        /// Releases the unmanaged resources used by this <see cref="BroPacket"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
#if USE_SAFE_HANDLES
                    if ((object)m_packetPtr != null && !m_packetPtr.IsInvalid())
                    {
                        m_packetPtr.Dispose();
                    }
#else
                    if (m_packetPtr != IntPtr.Zero)
                    {
                        BroApi.bro_packet_free(m_packetPtr);
                        m_packetPtr = IntPtr.Zero;
                    }
#endif
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Exemplo n.º 2
0
        internal BroPacket(IntPtr sourcePacketPtr)
#endif
        {
            if (!sourcePacketPtr.IsInvalid())
            {
                m_packetPtr = BroApi.bro_packet_clone(sourcePacketPtr);
            }
        }
Exemplo n.º 3
0
        // Creates a new Bro packet from libpcap packet header information and packet data.
        internal BroPacket(timeval timestamp, uint captureLength, byte[] packetData, string tag = null)
        {
            if ((object)packetData == null)
            {
                throw new ArgumentNullException("packetData");
            }

            pcap_pkthdr header = new pcap_pkthdr();

            header.ts     = timestamp;
            header.caplen = captureLength;
            header.len    = (uint)packetData.Length;

            m_packetPtr = BroApi.bro_packet_new(ref header, packetData, tag);

            if (m_packetPtr.IsInvalid())
            {
                throw new OutOfMemoryException("Failed to create Bro packet.");
            }
        }
Exemplo n.º 4
0
        // Create new BroPacket from an existing source packet - have to clone source packet since we don't own it
#if USE_SAFE_HANDLES
        internal BroPacket(BroPacketPtr sourcePacketPtr)