Ejemplo n.º 1
0
        public void Add(IPAddress addr, int prefix)
        {
            cachedHash = null;

            if (addr.IsIPv4MappedToIPv6)
            {
                // workaround for buggy MapToIPv4 implementation
                addr = Fixes.MapToIPv4(addr);
                if (prefix >= 96)
                {
                    prefix -= 96;
                }
            }

            if (addr.AddressFamily == AddressFamily.InterNetwork)
            {
                writer.Write((byte)F2B_FWDATA_TYPE0_ENUM.F2B_FWDATA_IPv4_AND_PREFIX);
            }
            else
            {
                writer.Write((byte)F2B_FWDATA_TYPE0_ENUM.F2B_FWDATA_IPv6_AND_PREFIX);
            }
            writer.Write(addr.GetAddressBytes());
            writer.Write((byte)prefix);
        }
Ejemplo n.º 2
0
        public void Add(IPAddress addrLow, IPAddress addrHigh)
        {
            cachedHash = null;

            if (addrLow.IsIPv4MappedToIPv6)
            {
                // workaround for buggy MapToIPv4 implementation
                addrLow = Fixes.MapToIPv4(addrLow);
            }
            if (addrHigh.IsIPv4MappedToIPv6)
            {
                // workaround for buggy MapToIPv4 implementation
                addrHigh = Fixes.MapToIPv4(addrHigh);
            }

            if (addrLow.AddressFamily != addrHigh.AddressFamily)
            {
                throw new ArgumentException("Unable to add rule with mixed IPv4 and IPv6 range");
            }

            if (addrLow.AddressFamily == AddressFamily.InterNetwork)
            {
                writer.Write((byte)F2B_FWDATA_TYPE0_ENUM.F2B_FWDATA_IPv4_RANGE);
            }
            else
            {
                writer.Write((byte)F2B_FWDATA_TYPE0_ENUM.F2B_FWDATA_IPv6_RANGE);
            }
            writer.Write(addrLow.GetAddressBytes());
            writer.Write(addrHigh.GetAddressBytes());
        }
Ejemplo n.º 3
0
        public void Add(IPAddress addr)
        {
            cachedHash = null;

            if (addr.IsIPv4MappedToIPv6)
            {
                // workaround for buggy MapToIPv4 implementation
                addr = Fixes.MapToIPv4(addr);
            }

            if (addr.AddressFamily == AddressFamily.InterNetwork)
            {
                writer.Write((byte)F2B_FWDATA_TYPE0_ENUM.F2B_FWDATA_IPv4);
            }
            else
            {
                writer.Write((byte)F2B_FWDATA_TYPE0_ENUM.F2B_FWDATA_IPv6);
            }
            writer.Write(addr.GetAddressBytes());
        }