/* * 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; } } }
/// <summary> /// Send a packet to find the DHCP server and tell that we want a new IP address /// </summary> public static void SendDiscoverPacket() { NetworkStack.RemoveAllConfigIP(); foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { NetworkInit.Enable(networkDevice, new Network.IPV4.Address(0, 0, 0, 0), new Network.IPV4.Address(0, 0, 0, 0), new Network.IPV4.Address(0, 0, 0, 0)); DHCPDiscover dhcp_discover = new DHCPDiscover(networkDevice.MACAddress); OutgoingBuffer.AddPacket(dhcp_discover); NetworkStack.Update(); DHCPAsked = true; } }
/// <summary> /// Send a packet to the DHCP server to make the address available again /// </summary> public void SendReleasePacket() { foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { Address source = IPConfig.FindNetwork(DHCPServerAddress(networkDevice)); var dhcp_release = new DHCPRelease(source, DHCPServerAddress(networkDevice), networkDevice.MACAddress); OutgoingBuffer.AddPacket(dhcp_release); NetworkStack.Update(); NetworkStack.RemoveAllConfigIP(); IPConfig.Enable(networkDevice, new Address(0, 0, 0, 0), new Address(0, 0, 0, 0), new Address(0, 0, 0, 0)); } Close(); }
/* * 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(); }
/// <summary> /// c = command, c_SystemInfomation /// </summary> public static void c_IPConfig(string cmd) { string[] args = cmd.Split(' '); if (args.Length == 1) { L.List_Translation.Ipconfig(); return; } if (args[1] == "/release") { System.Network.DHCP.Core.SendReleasePacket(); } else if (args[1] == "/set") { if (args.Length <= 3) { Console.WriteLine("Usage : " + args[0] + " /set {interface} {IPv4} {Subnet} -g {Gateway} -d {PrimaryDNS}"); //ipconfig /set PCNETII 192.168.1.32 255.255.255.0 -g 192.168.1.254 -d 8.8.8.8 } else { if (NetworkInterfaces.Interface(args[2]) != "null") { Utils.Settings settings = new Utils.Settings(@"0:\System\" + NetworkInterfaces.Interface(args[2]) + ".conf"); NetworkStack.RemoveAllConfigIP(); ApplyIP(args, settings); settings.Push(); NetworkInit.Enable(); } else { Console.WriteLine("This interface doesn't exists."); } } } else if (args[1] == "/renew") { System.Network.DHCP.Core.SendDiscoverPacket(); } else { L.List_Translation.Ipconfig(); } }
/// <summary> /// Send a packet to find the DHCP server and tell that we want a new IP address /// </summary> /// <returns>time value (-1 = timeout)</returns> public int SendDiscoverPacket() { NetworkStack.RemoveAllConfigIP(); foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { IPConfig.Enable(networkDevice, new Address(0, 0, 0, 0), new Address(0, 0, 0, 0), new Address(0, 0, 0, 0)); var dhcp_discover = new DHCPDiscover(networkDevice.MACAddress); OutgoingBuffer.AddPacket(dhcp_discover); NetworkStack.Update(); asked = true; } return(Receive()); }
/// <summary> /// Send a packet to the DHCP server to make the address available again /// </summary> public static void SendReleasePacket() { foreach (NetworkDevice networkDevice in NetworkDevice.Devices) { Address source = Config.FindNetwork(DHCPServerAddress(networkDevice)); DHCPRelease dhcp_release = new DHCPRelease(source, DHCPServerAddress(networkDevice)); OutgoingBuffer.AddPacket(dhcp_release); NetworkStack.Update(); NetworkStack.RemoveAllConfigIP(); Settings settings = new Settings(@"0:\" + networkDevice.Name + ".conf"); settings.EditValue("ipaddress", "0.0.0.0"); settings.EditValue("subnet", "0.0.0.0"); settings.EditValue("gateway", "0.0.0.0"); settings.EditValue("dns01", "0.0.0.0"); settings.PushValues(); NetworkInit.Enable(); } }
/* * 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> private 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) { throw new Exception("Parsing DHCP ACK Packet failed, can't apply network configuration."); } else { if (message) { Global.mDebugger.Send("[DHCP ACK][" + networkDevice.Name + "] Packet received, applying IP configuration..."); Global.mDebugger.Send(" IP Address : " + packet.Client.ToString()); Global.mDebugger.Send(" Subnet mask : " + packet.Subnet.ToString()); Global.mDebugger.Send(" Gateway : " + packet.Server.ToString()); Global.mDebugger.Send(" DNS server : " + packet.DNS.ToString()); } IPConfig.Enable(networkDevice, packet.Client, packet.Subnet, packet.Server); DNSConfig.Add(packet.DNS); if (message) { Global.mDebugger.Send("[DHCP CONFIG][" + networkDevice.Name + "] IP configuration applied."); asked = false; } } } Close(); }