// Ctor allows conversion from L4Packet to Connection. public Connection(IPV4_PACKET pkt) { Type = new ConnectionType(pkt.protocol); _state = new ConnectionState(TransmissionDirection.ONE_WAY); SrcHost = new ConnectionAddress(pkt.source_address); DstHost = new ConnectionAddress(pkt.destination_address); SrcPort = pkt.source_port; DstPort = pkt.destination_port; DstGeo = new GeoData(); _packetCount = 1; _dataSize = pkt.payload_size; TimeStamp = DateTime.Now; DstASN = null; DstASNOrg = "--"; }
// Match packet to connection (-1 = no match, 0 = match, 1 = reverse match. public MatchType PacketMatch(IPV4_PACKET pkt) { // Check protocol first (biggest devider of connections). if (!Equals(this.Type.Protocol, pkt.protocol)) { return(MatchType.NON_MATCH); } // Check if IP's and ports (or inverse) match. if ((Equals(this.SrcHost.Address, pkt.source_address) && Equals(this.SrcPort, pkt.source_port)) && (Equals(this.DstHost.Address, pkt.destination_address) && Equals(this.DstPort, pkt.destination_port))) { return(MatchType.MATCH); } else if ((Equals(this.SrcHost.Address, pkt.destination_address) && Equals(this.SrcPort, pkt.destination_port)) && (Equals(this.DstHost.Address, pkt.source_address) && Equals(this.DstPort, pkt.source_port))) { return(MatchType.REV_MATCH); } return(MatchType.NON_MATCH); }