internal override void EnterEvent()
        {
            client.StartNewTransaction();

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

            dhcp.TransactionID = client.TransactionID;
            dhcp.SetHardwareAddress(client.MacAddress);

#if ADVERTISE_CLIENT_ID
            // Add Client Identifier for self
            //
            // This is disabled because the Windows
            // DHCP server allocates us a different address with the
            // client id present if we networked booted.  Thus having the
            // identifier breaks static DHCP entries which we use
            // for test machines.
            EthernetAddress macAddress = client.MacAddress;
            dhcp.AddOption(DhcpClientID.Create(macAddress.GetAddressBytes()));
#endif

            // Add parameters we'd like to know about
            dhcp.AddOption(DhcpParameterRequest.Create(
                               DhcpClient.StandardRequestParameters
                               )
                           );
            // dhcp.AddOption(DhcpAutoConfigure.Create(0));
            client.Send(EthernetAddress.Broadcast, dhcp);
            client.ChangeState(new DhcpClientStateSelecting(client));
        }
        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);
        }
        private void Respond(DhcpFormat request, DhcpFormat.MessageType m)
        {
            DhcpFormat response = new DhcpFormat(m);

            response.TransactionID = request.TransactionID;

            EthernetAddress hwAddress = request.GetHardwareAddress();

            response.SetHardwareAddress(hwAddress);

            switch (m)
            {
            case DhcpFormat.MessageType.Offer:
                response.NextServerIPAddress = ServerAddress;
                response.AddOption(
                    DhcpIPAddressLeaseTime.Create(RebindingTime)
                    );
                goto case DhcpFormat.MessageType.Ack;

            case DhcpFormat.MessageType.Ack:
                response.YourIPAddress = HostAddress;
                assignedAddress        = HostAddress;
                FillOptions(request, response);
                break;

            case DhcpFormat.MessageType.Nak:
                // Nothing to do
                break;

            default:
                return;
            }
            SendResponsePacket(response);
        }
        private void FillOptions(DhcpFormat request, DhcpFormat response)
        {
            SortedList requestOptions = request.GetOptions();

            response.AddOption(DhcpServerID.Create(ServerAddress));
            response.AddOption(DhcpRenewalTime.Create(RenewalTime));
            response.AddOption(DhcpRebindingTime.Create(RebindingTime));

            foreach (IDhcpOption option in requestOptions.Values)
            {
                byte optionCode = option.OptionCode;
                Console.WriteLine("({0}) {1}",
                                  optionCode,
                                  DhcpOptionParser.GetOptionName(optionCode));
            }

            DhcpMultiByteOption parameters =
                requestOptions[DhcpParameterRequest.OptionCode]
                as DhcpMultiByteOption;

            if (parameters == null)
            {
                return;
            }

            foreach (byte parameter in parameters.Values)
            {
                switch (parameter)
                {
                case DhcpSubnetMask.OptionCode:
                    response.AddOption(DhcpSubnetMask.Create(NetMask));
                    break;

                case DhcpDomainName.OptionCode:
                    response.AddOption(
                        DhcpDomainName.Create(DomainName.ToCharArray())
                        );
                    break;

                case DhcpRouter.OptionCode:
                    response.AddOption(DhcpRouter.Create(Routers));
                    break;

                case DhcpDomainNameServer.OptionCode:
                    response.AddOption(
                        DhcpDomainNameServer.Create(DnsServers)
                        );
                    break;
                }
            }
        }