diff --git a/Docs/articles/Kernel/Network.md b/Docs/articles/Kernel/Network.md
index 18c9ba8f7..cb7abf44b 100644
--- a/Docs/articles/Kernel/Network.md
+++ b/Docs/articles/Kernel/Network.md
@@ -1,8 +1,8 @@
# Network
-In this article we will discuss about Networking on Cosmos, how to use the Network Stack, send and received packets. For now, available protocols are **ARP**, **IPv4**, **UDP**, **ICMP**, **DHCP** and **DNS** but the team is also working on TCP.
+In this article we will discuss about Networking on Cosmos, how to use the Network Stack, send and received packets. For now, available protocols are **ARP**, **IPv4**, **UDP**, **ICMP**, **DHCP** and **DNS** but the team is also working on TCP. Note that Cosmos devkit must be installed for this article.
-All protocols here don't necessary support every feature described by their RFC and may have some bugs or architecture issues, if you find something abnormal please [submit an issue](http://https://github.com/CosmosOS/Cosmos/issues/new/choose "repository") on our repository.
+All protocols here don't necessary support every feature described by their RFC and may have some bugs or architecture issues, if you find bugs or something abnormal please [submit an issue](http://https://github.com/CosmosOS/Cosmos/issues/new/choose "repository") on our repository.
Each protocol has a Client class which can be used to receive and send data. If a Receive() method is blocking, the method will timeout after 5 seconds or use the value optionally set by parameter. Please note that all finished connections should be closed using Close().
@@ -82,3 +82,8 @@ using(var xClient = new DnsClient())
xClient.Close();
}
```
+## Utils
+## Get local IP
+```csharp
+Console.WriteLine(NetworkConfig.CurrentConfig.Value.IPAddress.ToString());
+```
diff --git a/source/Cosmos.System2/Network/IPV4/UDP/DHCP/DHCPClient.cs b/source/Cosmos.System2/Network/IPV4/UDP/DHCP/DHCPClient.cs
index bb5349981..b712a28e9 100644
--- a/source/Cosmos.System2/Network/IPV4/UDP/DHCP/DHCPClient.cs
+++ b/source/Cosmos.System2/Network/IPV4/UDP/DHCP/DHCPClient.cs
@@ -21,7 +21,7 @@ namespace Cosmos.System.Network.IPv4.UDP.DHCP
//
/// Is DHCP ascked check variable
///
- protected bool asked = false;
+ private bool asked = false;
///
/// Get the IP address of the DHCP server
@@ -71,7 +71,7 @@ namespace Cosmos.System.Network.IPv4.UDP.DHCP
{
if (packet.RawData[284] == 0x02) //Offer packet received
{
- SendRequestPacket(packet.Client, packet.Server);
+ return SendRequestPacket(packet.Client, packet.Server);
}
else if (packet.RawData[284] == 0x05 || packet.RawData[284] == 0x06) //ACK or NAK DHCP packet received
{
@@ -98,7 +98,7 @@ namespace Cosmos.System.Network.IPv4.UDP.DHCP
foreach (NetworkDevice networkDevice in NetworkDevice.Devices)
{
Address source = IPConfig.FindNetwork(DHCPServerAddress(networkDevice));
- DHCPRelease dhcp_release = new DHCPRelease(source, DHCPServerAddress(networkDevice), networkDevice.MACAddress);
+ var dhcp_release = new DHCPRelease(source, DHCPServerAddress(networkDevice), networkDevice.MACAddress);
OutgoingBuffer.AddPacket(dhcp_release);
NetworkStack.Update();
@@ -113,7 +113,8 @@ namespace Cosmos.System.Network.IPv4.UDP.DHCP
///
/// Send a packet to find the DHCP server and tell that we want a new IP address
///
- public void SendDiscoverPacket()
+ /// time value (-1 = timeout)
+ public int SendDiscoverPacket()
{
NetworkStack.RemoveAllConfigIP();
@@ -121,28 +122,29 @@ namespace Cosmos.System.Network.IPv4.UDP.DHCP
{
IPConfig.Enable(networkDevice, new Address(0, 0, 0, 0), new Address(0, 0, 0, 0), new Address(0, 0, 0, 0));
- DHCPDiscover dhcp_discover = new DHCPDiscover(networkDevice.MACAddress);
+ var dhcp_discover = new DHCPDiscover(networkDevice.MACAddress);
OutgoingBuffer.AddPacket(dhcp_discover);
NetworkStack.Update();
asked = true;
}
- Receive();
+ return Receive();
}
///
/// Send a request to apply the new IP configuration
///
- private void SendRequestPacket(Address RequestedAddress, Address DHCPServerAddress)
+ /// time value (-1 = timeout)
+ private int SendRequestPacket(Address RequestedAddress, Address DHCPServerAddress)
{
foreach (NetworkDevice networkDevice in NetworkDevice.Devices)
{
- DHCPRequest dhcp_request = new DHCPRequest(networkDevice.MACAddress, RequestedAddress, DHCPServerAddress);
+ var dhcp_request = new DHCPRequest(networkDevice.MACAddress, RequestedAddress, DHCPServerAddress);
OutgoingBuffer.AddPacket(dhcp_request);
NetworkStack.Update();
}
- Receive();
+ return Receive();
}
/*
diff --git a/source/Cosmos.System2/Network/IPV4/UDP/DNS/DNSClient.cs b/source/Cosmos.System2/Network/IPV4/UDP/DNS/DNSClient.cs
index dec08b9bc..58dca96a8 100644
--- a/source/Cosmos.System2/Network/IPV4/UDP/DNS/DNSClient.cs
+++ b/source/Cosmos.System2/Network/IPV4/UDP/DNS/DNSClient.cs
@@ -50,7 +50,7 @@ namespace Cosmos.System.Network.IPv4.UDP.DNS
queryurl = url;
- DNSPacketAsk askpacket = new DNSPacketAsk(source, destination, url);
+ var askpacket = new DNSPacketAsk(source, destination, url);
OutgoingBuffer.AddPacket(askpacket);
@@ -81,7 +81,7 @@ namespace Cosmos.System.Network.IPv4.UDP.DNS
}
}
- DNSPacketAnswer packet = new DNSPacketAnswer(rxBuffer.Dequeue().RawData);
+ var packet = new DNSPacketAnswer(rxBuffer.Dequeue().RawData);
if ((ushort)(packet.DNSFlags & 0x0F) == (ushort)ReplyCode.OK)
{
diff --git a/source/Cosmos.System2/Network/IPv4/UDP/UdpClient.cs b/source/Cosmos.System2/Network/IPv4/UDP/UdpClient.cs
index 46c24ab24..8aa440df1 100644
--- a/source/Cosmos.System2/Network/IPv4/UDP/UdpClient.cs
+++ b/source/Cosmos.System2/Network/IPv4/UDP/UdpClient.cs
@@ -25,20 +25,20 @@ namespace Cosmos.System.Network.IPv4.UDP
///
/// Local port.
///
- protected int localPort;
+ private int localPort;
///
/// Destination address.
///
- protected Address destination;
+ internal Address destination;
///
/// Destination port.
///
- protected int destinationPort;
+ private int destinationPort;
///
/// RX buffer queue.
///
- protected Queue rxBuffer;
+ internal Queue rxBuffer;
///
/// Assign clients dictionary.