コード例 #1
0
    public void Request(DhcpMessage requestMessage)
    {
        PresentedName = requestMessage.HostName ?? PresentedName;
        if (State == DhcpState.Forbidden)
        {
            AddEvent(new DhcpRequestRejectedEvent(this, requestMessage));
        }

        var clientOffer = requestMessage.ClientIPAddress;

        if (requestMessage.Options.TryGetValue(DhcpMessage.DhcpOptionCode.RequestedIpAddress,
                                               out var requestedIpAddress))
        {
            clientOffer = new IPAddress(requestedIpAddress);
        }

        if (clientOffer.Equals(ClientAddress))
        {
            State = DhcpState.Accepted;
            AddEvent(new DhcpRequestAcceptedEvent(this, requestMessage));
        }
        else
        {
            AddEvent(new DhcpRequestRejectedEvent(this, requestMessage));
        }
    }
コード例 #2
0
 public NetworkDevice(PhysicalAddress id, string name, IPAddress clientAddress, bool permanent, NetworkConfiguration?preferredConfiguration)
 {
     Id                     = id;
     Name                   = name;
     ClientAddress          = clientAddress;
     Permanent              = permanent;
     UpdateTime             = DateTime.Now;
     LeaseTimeSeconds       = (int)TimeSpan.FromDays(1).TotalSeconds;
     PreferredConfiguration = preferredConfiguration;
     State                  = DhcpState.Unknown;
 }
コード例 #3
0
    public void Discover(DhcpMessage discoverMessage)
    {
        PresentedName = discoverMessage.HostName ?? PresentedName;

        if (State == DhcpState.Offered && UpdateTime.AddSeconds(10) > DateTime.Now)
        {
            return;
        }

        if (State == DhcpState.Forbidden)
        {
            AddEvent(new DhcpRequestRejectedEvent(this, discoverMessage));
        }
        else
        {
            UpdateTime = DateTime.Now;
            State      = DhcpState.Offered;
            AddEvent(new DhcpRequestAcceptedEvent(this, discoverMessage));
        }
    }