Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
        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);
        }