Exemplo n.º 1
0
        public bool QueryPackets(ulong startTime, ulong endTime, List<int> protocolList, OCurrentPacketList curPackets)
        {
            if (null == _dbConnection)
            {
                return false;
            }

            // Build Query statement
            string sql = BuildSQLStatement(startTime, endTime, protocolList);
            SQLiteCommand command = new SQLiteCommand(sql, _dbConnection);
            SQLiteDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                OPacket pac = new OPacket();
                pac.SetTimeCollected((ulong)(Int64)reader[0]);
                pac.SetSourceIP((string)reader[1]);
                pac.SetDestinationIP((string)reader[2]);
                pac.SetProtocol((int)(Int64)reader[3]);
                pac.SetLength((int)(Int64)reader[4]);
                pac.SetPacketStoredPath((string)reader[5]);

                curPackets.AddPacket(pac);
            }
            return true;
        }
Exemplo n.º 2
0
        public void SavePacket(OPacket packet, byte[] rawData)
        {
            if (null == _dbConnection)
            {
                return;
            }

            // Save packet data into the file system
            string _path = OArchive.GetArchiveFolder();
            _path += "\\";
            _path += _GetTempName();

            // Save packet data
            if (false == _SavePacketAsFile(_path, rawData))
            {
                return;
            }

            packet.SetPacketStoredPath(_path);

            // Save into the Database
            string sql = "INSERT INTO packets (collected_time, src_ip, dest_ip, dest_port, length, packet_path) values ";
            string sqlValue = "(";
            sqlValue += packet.GetTimeCollected();
            sqlValue += ", ";
            sqlValue += "\"";
            sqlValue += packet.GetSourceIP();
            sqlValue += "\"";
            sqlValue += ", ";
            sqlValue += "\"";
            sqlValue += packet.GetDestinationIP();
            sqlValue += "\"";
            sqlValue += ", ";
            sqlValue += Convert.ToString(packet.GetProtocol());
            sqlValue += ", ";
            sqlValue += "\"";
            sqlValue += Convert.ToString(packet.GetLength());
            sqlValue += "\"";
            sqlValue += ", ";
            sqlValue += "\"";
            sqlValue += packet.GetPacketStoredPath();
            sqlValue += "\"";
            sqlValue += ")";
            sql += sqlValue;
            SQLiteCommand command = new SQLiteCommand(sql, _dbConnection);
            command.ExecuteNonQuery();
        }