Пример #1
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));
        }
Пример #2
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));
        }
 public DhcpServerIpAddress DataAsIpAddress() => DhcpServerIpAddress.FromNative(DataAsInt32());
 public DhcpServerIpAddress DataAsIpAddress(int index) => DhcpServerIpAddress.FromNative(DataAsInt32(index));