Ejemplo n.º 1
0
 internal static DhcpServerIpRange FromNative(ref DHCP_BOOTP_IP_RANGE native, DhcpServerIpRangeType type)
 {
     return(new DhcpServerIpRange(startAddress: native.StartAddress.AsNetworkToIpAddress(),
                                  endAddress: native.EndAddress.AsNetworkToIpAddress(),
                                  type: type,
                                  bootpClientsAllocated: native.BootpAllocated,
                                  maxBootpAllowed: native.MaxBootpAllowed));
 }
Ejemplo n.º 2
0
        private DhcpServerIpRange(DhcpServerIpAddress startAddress, DhcpServerIpAddress endAddress, DhcpServerIpRangeType type, int bootpClientsAllocated, int maxBootpAllowed)
        {
            if (startAddress > endAddress)
            {
                throw new ArgumentOutOfRangeException(nameof(endAddress), "The ip range start address cannot be greater than the end address");
            }

            this.startAddress          = startAddress;
            this.endAddress            = endAddress;
            this.type                  = type;
            this.bootpClientsAllocated = bootpClientsAllocated;
            this.maxBootpAllowed       = maxBootpAllowed;
        }
Ejemplo n.º 3
0
        private static DhcpServerIpRange FromCidr(string cidrSubnet, DhcpServerIpRangeType type, int bootpClientsAllocated, int maxBootpAllowed)
        {
            if (string.IsNullOrEmpty(cidrSubnet))
            {
                throw new ArgumentNullException(nameof(cidrSubnet));
            }

            var slashIndex = cidrSubnet.IndexOf('/');

            if (slashIndex < 7 || !BitHelper.TryParseByteFromSubstring(cidrSubnet, ++slashIndex, cidrSubnet.Length - slashIndex, out var significantBits))
            {
                throw new ArgumentException("Invalid CIDR subnet notation format");
            }

            var address = DhcpServerIpAddress.FromNative(BitHelper.StringToIpAddress(cidrSubnet, 0, --slashIndex));
            var mask    = DhcpServerIpMask.FromSignificantBits(significantBits);

            return(FromMask(address, mask, type, bootpClientsAllocated, maxBootpAllowed));
        }
Ejemplo n.º 4
0
        private static DhcpServerIpRange FromMask(DhcpServerIpAddress address, DhcpServerIpMask mask, DhcpServerIpRangeType type, int bootpClientsAllocated, int maxBootpAllowed)
        {
            var startAddressNative = address.Native & mask.Native;
            var endAddressNative   = (address.Native & mask.Native) | ~mask.Native;

            if (type == DhcpServerIpRangeType.ScopeDhcpOnly ||
                type == DhcpServerIpRangeType.ScopeDhcpAndBootp ||
                type == DhcpServerIpRangeType.ScopeBootpOnly)
            {
                // remove subnet id and broadcast address from range
                startAddressNative++;
                endAddressNative--;
            }

            return(new DhcpServerIpRange(startAddress: DhcpServerIpAddress.FromNative(startAddressNative),
                                         endAddress: DhcpServerIpAddress.FromNative(endAddressNative),
                                         type: type,
                                         bootpClientsAllocated: bootpClientsAllocated,
                                         maxBootpAllowed: maxBootpAllowed));
        }
Ejemplo n.º 5
0
 internal static DhcpServerIpRange FromMask(DhcpServerIpAddress address, DhcpServerIpMask mask, DhcpServerIpRangeType type)
 => FromMask(address, mask, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed);
Ejemplo n.º 6
0
 private DhcpServerIpRange(DhcpServerIpAddress startAddress, DhcpServerIpAddress endAddress, DhcpServerIpRangeType type)
     : this(startAddress, endAddress, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed)
 {
 }
Ejemplo n.º 7
0
 internal static DhcpServerIpRange FromNative(ref DHCP_IP_RANGE native, DhcpServerIpRangeType type)
 {
     return(new DhcpServerIpRange(startAddress: native.StartAddress.AsNetworkToIpAddress(),
                                  endAddress: native.EndAddress.AsNetworkToIpAddress(),
                                  type: type));
 }
Ejemplo n.º 8
0
 private static DhcpServerIpRange FromCidr(string cidrSubnet, DhcpServerIpRangeType type)
 => FromCidr(cidrSubnet, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed);
Ejemplo n.º 9
0
 internal DhcpServerIpRange GetIpRange(DhcpServerIpAddress address, DhcpServerIpRangeType type) => DhcpServerIpRange.FromMask(address, this, type);