Ejemplo n.º 1
0
        public static void DHCPHandler(byte[] packetData)
        {
            DHCPOption Options = new DHCPOption(packetData);

            if (Options.Type == 0x02)
            {
                //Offert packet received
                Core.SendRequestPacket(Options.Address(), Options.Server());
            }

            if (Options.Type == 0x05 || Options.Type == 0x06)
            {
                //ACK or NAK DHCP packet received
                if (Core.DHCPAsked)
                {
                    Core.Apply(Options, true);
                }
                else
                {
                    Core.Apply(Options);
                }
            }
        }
Ejemplo n.º 2
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(DHCPOption Options, 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 (message)
                {
                    Console.WriteLine();
                    CustomConsole.WriteLineInfo("[DHCP ACK][" + networkDevice.Name + "] Packet received, applying IP configuration...");
                    CustomConsole.WriteLineInfo("   IP Address  : " + Options.Address().ToString());
                    CustomConsole.WriteLineInfo("   Subnet mask : " + Options.Subnet().ToString());
                    CustomConsole.WriteLineInfo("   Gateway     : " + Options.Gateway().ToString());
                    CustomConsole.WriteLineInfo("   DNS server  : " + Options.DNS01().ToString());
                }

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

                NetworkInit.Enable(networkDevice, Options.Address(), Options.Subnet(), Options.Gateway());

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

            Kernel.BeforeCommand();
        }