Example #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(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();
                    Console.WriteLine("[DHCP ACK][" + networkDevice.Name + "] Packet received, applying IP configuration...");
                    Console.WriteLine("   IP Address  : " + Options.Address().ToString());
                    Console.WriteLine("   Subnet mask : " + Options.Subnet().ToString());
                    Console.WriteLine("   Gateway     : " + Options.Gateway().ToString());
                    Console.WriteLine("   DNS server  : " + Options.DNS01().ToString());
                }

                Settings settings = new Settings(@"0:\" + 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();

                if (message)
                {
                    Console.WriteLine("[DHCP CONFIG][" + networkDevice.Name + "] IP configuration applied.");
                    Console.WriteLine();
                    DHCPAsked = false;
                }
            }
        }
Example #2
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);
                }
            }
        }