public IPRule(string username, UInt16[] ipAddress, UInt16 mask, bool isAllowed) : base(username, isAllowed) { if (ipAddress.Length != 4) { throw new ArgumentException("ipAddress should have four octets"); } myIPAddress = ipAddress; myMask = mask; myMaskedIPAddress = IPUtils.ApplyMask(myMask, myIPAddress); }
private HashSet <uint> FindRulesMatchingIP(Packet packet) { HashSet <uint> maskedIPRuleSet = new HashSet <uint>(); foreach (UInt16 mask in myMaskedIPToRuleMap.Keys) { uint maskedPacketIP = IPUtils.ApplyMask(mask, packet.IPAddress); Dictionary <uint, HashSet <uint> > ipRuleMap = null; if (myMaskedIPToRuleMap.TryGetValue(mask, out ipRuleMap)) { HashSet <uint> ruleSet = null; ipRuleMap.TryGetValue(maskedPacketIP, out ruleSet); if (ruleSet != null && ruleSet.Count != 0) { maskedIPRuleSet.UnionWith(ruleSet); } } } return(maskedIPRuleSet); }