Exemple #1
0
        /// <summary>
        /// Releases the unmanaged resources used by this <see cref="BroConnection"/> 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_connectionPtr != null && !m_connectionPtr.IsInvalid())
                    {
                        m_connectionPtr.Dispose();
                    }
#else
                    if (m_connectionPtr != IntPtr.Zero)
                    {
                        BroApi.bro_conn_delete(m_connectionPtr);
                        m_connectionPtr = IntPtr.Zero;
                    }
#endif
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a new <see cref="BroConnection"/> using the existing <paramref name="socket"/> handle.
        /// </summary>
        /// <param name="socket">Existing open socket to use for <see cref="BroConnection"/>.</param>
        /// <param name="flags">Connection flags for this <see cref="BroConnection"/>.</param>
        /// <exception cref="OutOfMemoryException">Failed to create Bro connection.</exception>
        public BroConnection(int socket, BroConnectionFlags flags = BroConnectionFlags.None)
            : this()
        {
            m_connectionPtr = BroApi.bro_conn_new_socket(socket, flags);

            if (m_connectionPtr.IsInvalid())
            {
                throw new OutOfMemoryException("Failed to create Bro connection.");
            }

            m_hostName = string.Format("@FD={0}", socket);
            m_flags    = flags;
        }
Exemple #3
0
        /// <summary>
        /// Creates a new <see cref="BroConnection"/> with specified connection parameters.
        /// </summary>
        /// <param name="hostName">Host name, formatted as host:port, to connect to.</param>
        /// <param name="flags">Connection flags for this <see cref="BroConnection"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="hostName"/> is <c>null</c>.</exception>
        /// <exception cref="OutOfMemoryException">Failed to create Bro connection.</exception>
        public BroConnection(string hostName, BroConnectionFlags flags = BroConnectionFlags.None)
            : this()
        {
            if ((object)hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }

            m_connectionPtr = BroApi.bro_conn_new_str(hostName, flags);

            if (m_connectionPtr.IsInvalid())
            {
                throw new OutOfMemoryException("Failed to create Bro connection.");
            }

            m_hostName = hostName;
            m_flags    = flags;
        }
Exemple #4
0
        public BroConnection(Socket socket, BroConnectionFlags flags = BroConnectionFlags.None)
            : this()
        {
            if ((object)socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            m_connectionPtr = BroApi.bro_conn_new_socket(socket.Handle.ToInt32(), flags);

            if (m_connectionPtr.IsInvalid())
            {
                throw new OutOfMemoryException("Failed to create Bro connection.");
            }

            m_hostName = DeriveHostName(socket);
            m_flags    = flags;
        }
        // Get pointer to parent Bro connection
#if USE_SAFE_HANDLES
        private BroConnectionPtr GetConnectionPtr()
        {
            BroConnectionPtr connection = m_getValuePtr();
Exemple #6
0
        // Call-back handler for Bro compact event function
#if USE_SAFE_HANDLES
        private unsafe void BroCompactEventCallBack(BroConnectionPtr bc, IntPtr user_data, bro_ev_meta *meta)