private DhcpServerBindingElement(DhcpServer server, bool cantModify, bool isBound, DhcpServerIpAddress adapterPrimaryIpAddress, DhcpServerIpMask adapterSubnetAddress, string interfaceDescription, Guid interfaceGuidId, byte[] interfaceId)
 {
     Server     = server;
     CantModify = cantModify;
     IsBound    = isBound;
     AdapterPrimaryIpAddress = adapterPrimaryIpAddress;
     AdapterSubnetAddress    = adapterSubnetAddress;
     InterfaceDescription    = interfaceDescription;
     this.interfaceId        = interfaceId;
     InterfaceGuidId         = interfaceGuidId;
 }
示例#2
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));
        }
示例#3
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));
        }
 /// <summary>
 /// Creates a new DHCP Scope
 /// </summary>
 /// <param name="name">Name of the DHCP Scope</param>
 /// <param name="comment">Comment for the DHCP Scope</param>
 /// <param name="ipRange">IP Range to be associated with the DHCP Scope</param>
 /// <param name="mask">Subnet mask to be associated with the DHCP Scope</param>
 /// <param name="timeDelayOffer">Milliseconds to wait before sending a lease offer (maximum 1 second)</param>
 /// <param name="leaseDuration">Number of seconds the lease is held for</param>
 /// <returns></returns>
 public IDhcpServerScope AddScope(string name, string comment, DhcpServerIpRange ipRange, DhcpServerIpMask mask, TimeSpan timeDelayOffer, TimeSpan?leaseDuration)
 => DhcpServerScope.CreateScope(Server, name, comment, ipRange, mask, timeDelayOffer, leaseDuration);
 /// <summary>
 /// Creates a new DHCP Scope
 /// </summary>
 /// <param name="name">Name of the DHCP Scope</param>
 /// <param name="comment">Comment for the DHCP Scope</param>
 /// <param name="ipRange">IP Range to be associated with the DHCP Scope</param>
 /// <param name="mask">Subnet mask to be associated with the DHCP Scope</param>
 /// <returns>Newly created DHCP Scope</returns>
 public IDhcpServerScope AddScope(string name, string comment, DhcpServerIpRange ipRange, DhcpServerIpMask mask)
 => DhcpServerScope.CreateScope(Server, name, comment, ipRange, mask);
示例#6
0
 internal static DhcpServerIpRange FromMask(DhcpServerIpAddress address, DhcpServerIpMask mask, DhcpServerIpRangeType type)
 => FromMask(address, mask, type, DefaultBootpClientsAllocated, DefaultMaxBootpAllowed);
示例#7
0
 public static DhcpServerIpRange AsExcluded(DhcpServerIpAddress address, DhcpServerIpMask mask)
 => FromMask(address, mask, DhcpServerIpRangeType.Excluded);
示例#8
0
 public static DhcpServerIpRange AsDhcpScope(DhcpServerIpAddress address, DhcpServerIpMask mask)
 => FromMask(address, mask, DhcpServerIpRangeType.ScopeDhcpOnly);
示例#9
0
 public static DhcpServerIpRange AsBootpScope(DhcpServerIpAddress address, DhcpServerIpMask mask, int bootpClientsAllocated = DefaultBootpClientsAllocated, int maxBootpAllowed = DefaultMaxBootpAllowed)
 => FromMask(address, mask, DhcpServerIpRangeType.ScopeBootpOnly, bootpClientsAllocated, maxBootpAllowed);
示例#10
0
 public void AddExcludedIpRange(DhcpServerIpAddress address, DhcpServerIpMask mask)
 => DhcpServerScope.AddSubnetExcludedIpRangeElement(Server, Scope.Address, DhcpServerIpRange.AsExcluded(address, mask));