//Verify each packet against the ACL public void VerifyPacket(Packet packet) { bool packetPermitted = false; foreach (Rule tempRule in access_list) { if (addrIsMatch(tempRule.source, packet.source, tempRule.mask)) { //see if rule is for permit or deny bool access = false; if (tempRule.permission == "deny") access = false; else if (tempRule.permission == "permit") access = true; else throw new Exception("Invalid rule permission - must be \'Permit\' or \'Deny\'"); if (access) { packetPermitted = true; } else break; } } Console.WriteLine("Source: " + packet.source + " Destination: " + packet.destination + " Access: " + (packetPermitted ? "Permit" : "Deny")); }
//read packets from file and return a list of packet objects static List<Packet> readPackets() { string line; List<Packet> packets = new List<Packet>(); using (StreamReader pack = new StreamReader(@"packets.txt")) { while ((line = pack.ReadLine()) != null) { string source = line.Substring(0, line.IndexOf(" ")); string destination = line.Substring(line.IndexOf(" ")); Packet tempPacket = new Packet(source, destination); packets.Add(tempPacket); } } return packets; }