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)); }
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; }
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)); }
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)); }
internal static DhcpServerIpRange FromMask(DhcpServerIpAddress address, DhcpServerIpMask mask, DhcpServerIpRangeType type) => FromMask(address, mask, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed);
private DhcpServerIpRange(DhcpServerIpAddress startAddress, DhcpServerIpAddress endAddress, DhcpServerIpRangeType type) : this(startAddress, endAddress, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed) { }
internal static DhcpServerIpRange FromNative(ref DHCP_IP_RANGE native, DhcpServerIpRangeType type) { return(new DhcpServerIpRange(startAddress: native.StartAddress.AsNetworkToIpAddress(), endAddress: native.EndAddress.AsNetworkToIpAddress(), type: type)); }
private static DhcpServerIpRange FromCidr(string cidrSubnet, DhcpServerIpRangeType type) => FromCidr(cidrSubnet, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed);
internal DhcpServerIpRange GetIpRange(DhcpServerIpAddress address, DhcpServerIpRangeType type) => DhcpServerIpRange.FromMask(address, this, type);