public MemoryFirewallRuleRanges(List <IPAddressRange> blockRanges, List <PortRange> allowPorts) { foreach (IPAddressRange range in blockRanges) { // optimized storage, no pointers or other overhead if (range.Begin.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { uint begin = range.Begin.ToUInt32(); uint end = range.End.ToUInt32(); Debug.Assert(end >= begin); ipv4.Add(new IPV4Range { Begin = begin, End = end }); } else { UInt128 begin = range.Begin.ToUInt128(); UInt128 end = range.End.ToUInt128(); Debug.Assert(end.CompareTo(begin) >= 0); ipv6.Add(new IPV6Range { Begin = begin, End = end }); } } ipv4.TrimExcess(); ipv6.TrimExcess(); this.allowPorts = allowPorts; }
public MemoryFirewallRuleRanges(List <IPAddressRange> ipRanges, List <PortRange> allowedPorts, bool block) { allowedPorts = (allowedPorts ?? new List <PortRange>(0)); foreach (IPAddressRange range in ipRanges) { // optimized storage, no pointers or other overhead if (range.Begin.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { uint begin = range.Begin.ToUInt32(); uint end = range.End.ToUInt32(); Debug.Assert(end >= begin); ipv4.Add(new IPV4Range { Begin = begin, End = end }); } else { UInt128 begin = range.Begin.ToUInt128(); UInt128 end = range.End.ToUInt128(); Debug.Assert(end.CompareTo(begin) >= 0); ipv6.Add(new IPV6Range { Begin = begin, End = end }); } } ipv4.TrimExcess(); ipv6.TrimExcess(); if (block) { string portString = IPBanFirewallUtility.GetPortRangeStringBlockExcept(allowedPorts); this.portRanges = (string.IsNullOrWhiteSpace(portString) ? new List <PortRange>(0) : portString.Split(',').Select(s => PortRange.Parse(s)).ToList()); } else { this.portRanges = allowedPorts; } }