예제 #1
0
        internal override void EnterEvent()
        {
            client.SetStateTimeout(DateTime.Now + StateTimeout);

            DhcpFormat dhcp =
                new DhcpFormat(DhcpFormat.MessageType.Request);

            dhcp.TransactionID      = client.TransactionID;
            dhcp.TransactionSeconds = client.TransactionSeconds;
            dhcp.SetHardwareAddress(client.MacAddress);
#if ADVERTISE_CLIENT_ID
            dhcp.AddOption(
                DhcpClientID.Create(client.MacAddress.GetAddressBytes())
                );
#endif
            dhcp.AddOption(
                DhcpRequestedIPAddress.Create(offeredAddress)
                );

            // Add parameters we'd like to know about
            dhcp.AddOption(DhcpParameterRequest.Create(
                               DhcpClient.StandardRequestParameters
                               )
                           );

            client.Send(EthernetAddress.Broadcast, dhcp);
        }
예제 #2
0
        internal override void EnterEvent()
        {
            // Yay! We got DHCP configuration information
            DateTime now = DateTime.Now;

            // Set up renewal timer
            DhcpDWordOption renewalOption =
                hostOptions[DhcpRenewalTime.OptionCode] as DhcpDWordOption;

            uint renewalSeconds = 3600;

            if (renewalOption != null)
            {
                renewalSeconds = renewalOption.Value;
            }
            client.SetRenewalTimeout(now + TimeSpan.FromSeconds(renewalSeconds));

            // Set up rebinding timer
            DhcpDWordOption rebindOption =
                hostOptions[DhcpRebindingTime.OptionCode] as DhcpDWordOption;
            uint rebindSeconds = renewalSeconds + 60;

            if (rebindOption != null)
            {
                rebindSeconds = Math.Max(rebindOption.Value,
                                         renewalSeconds + 1);
            }
            client.SetRebindTimeout(now + TimeSpan.FromSeconds(rebindSeconds));

            // Add host address as a dhcp option and then get client
            // to install settings.
            hostOptions[DhcpRequestedIPAddress.OptionCode] =
                DhcpRequestedIPAddress.Create(hostAddress);

            if (client.InstallDhcpOptions(hostOptions) == false)
            {
                client.ChangeState(new DhcpClientStateInitialize(client));
            }
            DebugStub.Print("DHCP client acquired lease of " + hostAddress + " for " + rebindSeconds + " seconds. ");
        }