Esempio n. 1
0
        /*
         * Method called to applied the differents options received in the DHCP packet ACK
         **/
        /// <summary>
        /// Apply the new IP configuration received.
        /// </summary>
        /// <param name="Options">DHCPOption class using the packetData from the received dhcp packet.</param>
        /// <param name="message">Enable/Disable the displaying of messages about DHCP applying and conf. Disabled by default.
        /// </param>
        public static void Apply(DHCPAck packet, bool message = false)
        {
            NetworkStack.RemoveAllConfigIP();

            //cf. Roadmap. (have to change this, because some network interfaces are not configured in dhcp mode) [have to be done in 0.5.x]
            foreach (NetworkDevice networkDevice in NetworkDevice.Devices)
            {
                if (packet.Client.ToString() == null ||
                    packet.Client.ToString() == null ||
                    packet.Client.ToString() == null ||
                    packet.Client.ToString() == null)
                {
                    CustomConsole.WriteLineError("Parsing DHCP ACK Packet failed, can't apply network configuration.");
                }
                else
                {
                    if (message)
                    {
                        Console.WriteLine();
                        CustomConsole.WriteLineInfo("[DHCP ACK][" + networkDevice.Name + "] Packet received, applying IP configuration...");
                        CustomConsole.WriteLineInfo("   IP Address  : " + packet.Client.ToString());
                        CustomConsole.WriteLineInfo("   Subnet mask : " + packet.Subnet.ToString());
                        CustomConsole.WriteLineInfo("   Gateway     : " + packet.Server.ToString());
                        CustomConsole.WriteLineInfo("   DNS server  : " + packet.DNS.ToString());
                    }

                    Utils.Settings settings = new Utils.Settings(@"0:\System\" + networkDevice.Name + ".conf");
                    settings.EditValue("ipaddress", packet.Client.ToString());
                    settings.EditValue("subnet", packet.Subnet.ToString());
                    settings.EditValue("gateway", packet.Server.ToString());
                    settings.EditValue("dns01", packet.DNS.ToString());
                    settings.EditValue("dhcp_server", packet.Server.ToString());
                    settings.PushValues();

                    NetworkInit.Enable(networkDevice, packet.Client, packet.Subnet, packet.Server, packet.DNS);

                    if (message)
                    {
                        CustomConsole.WriteLineOK("[DHCP CONFIG][" + networkDevice.Name + "] IP configuration applied.");
                        Console.WriteLine();
                        DHCPAsked = false;
                    }
                }
            }

            Kernel.BeforeCommand();
        }
Esempio n. 2
0
        public static void DHCPHandler(byte[] packetData)
        {
            DHCPPacket packet = new DHCPPacket(packetData);

            if (packet.messageType == 2)         //Boot Reply
            {
                if (packet.RawData[284] == 0x02) //Offer packet received
                {
                    DHCPClient.SendRequestPacket(packet.yourClient, packet.nextServer);
                }
                else if (packet.RawData[284] == 0x05 || packet.RawData[284] == 0x06) //ACK or NAK DHCP packet received
                {
                    DHCPAck ack = new DHCPAck(packetData);
                    if (DHCPClient.DHCPAsked)
                    {
                        DHCPClient.Apply(ack, true);
                    }
                    else
                    {
                        DHCPClient.Apply(ack);
                    }
                }
            }
        }