예제 #1
0
        private bool _ParsePacket(RawCapture r, OPacket p)
        {
            Packet packet = PacketDotNet.Packet.ParsePacket(r.LinkLayerType, r.Data);
            IpPacket ip = PacketDotNet.IpPacket.GetEncapsulated(packet);
            if (null == ip)
            {
                return false;
            }
            p.SetSourceIP(ip.SourceAddress.ToString());
            p.SetDestinationIP(ip.DestinationAddress.ToString());
            p.SetLength(r.Data.Length);
            p.SetTimeCollected(r.Timeval.Seconds);
            TcpPacket tcp = PacketDotNet.TcpPacket.GetEncapsulated(packet);
            if (null != tcp)
            {
                p.SetProtocol(tcp.DestinationPort);
                return true;
            }
//            UdpPacket udp = PacketDotNet.UdpPacket.GetEncapsulated(packet);
//            if (null != udp)
//            {
//                p.SetProtocol(udp.DestinationPort);
//                return true;
//            }

            return false;
        }
예제 #2
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;
        }