mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
Rename Client to GetClient + some code clean + Add rewrite
This commit is contained in:
parent
584568bceb
commit
eaf05f4c57
8 changed files with 26 additions and 22 deletions
|
|
@ -33,7 +33,9 @@ namespace Cosmos.HAL.Network
|
|||
public MACAddress(byte[] address)
|
||||
{
|
||||
if (address == null || address.Length != 6)
|
||||
{
|
||||
throw new ArgumentException("MACAddress is null or has wrong length", "address");
|
||||
}
|
||||
|
||||
bytes[0] = address[0];
|
||||
bytes[1] = address[1];
|
||||
|
|
@ -52,7 +54,9 @@ namespace Cosmos.HAL.Network
|
|||
public MACAddress(byte[] buffer, int offset)
|
||||
{
|
||||
if (buffer == null || buffer.Length < (offset + 6))
|
||||
{
|
||||
throw new ArgumentException("buffer does not contain enough data starting at offset", "buffer");
|
||||
}
|
||||
|
||||
bytes[0] = buffer[offset];
|
||||
bytes[1] = buffer[offset + 1];
|
||||
|
|
@ -95,7 +99,9 @@ namespace Cosmos.HAL.Network
|
|||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("obj is not a MACAddress", "obj");
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
|
@ -112,17 +118,19 @@ namespace Cosmos.HAL.Network
|
|||
bytes[5] == other.bytes[5];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("obj is not a MACAddress", "obj");
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (GetType().AssemblyQualifiedName + "|" + this.ToString()).GetHashCode();
|
||||
return (GetType().AssemblyQualifiedName + "|" + ToString()).GetHashCode();
|
||||
}
|
||||
|
||||
public UInt64 ToNumber()
|
||||
public ulong ToNumber()
|
||||
{
|
||||
return (UInt64)((bytes[0] << 40) | (bytes[1] << 32) | (bytes[2] << 24) | (bytes[3] << 16) |
|
||||
return (ulong)((bytes[0] << 40) | (bytes[1] << 32) | (bytes[2] << 24) | (bytes[3] << 16) |
|
||||
(bytes[4] << 8) | (bytes[5] << 0));
|
||||
}
|
||||
|
||||
|
|
@ -133,23 +141,23 @@ namespace Cosmos.HAL.Network
|
|||
aChars[aIndex + 1] = xChars[aByte & 0xF];
|
||||
}
|
||||
|
||||
public UInt32 to32BitNumber()
|
||||
public uint To32BitNumber()
|
||||
{
|
||||
return (UInt32)((bytes[0] << 40) | (bytes[1] << 32) | (bytes[2] << 24) | (bytes[3] << 16) |
|
||||
return (uint)((bytes[0] << 40) | (bytes[1] << 32) | (bytes[2] << 24) | (bytes[3] << 16) |
|
||||
(bytes[4] << 8) | (bytes[5] << 0));
|
||||
}
|
||||
|
||||
private UInt32 hash;
|
||||
private uint hash;
|
||||
/// <summary>
|
||||
/// Hash value for this mac. Used to uniquely identify each mac
|
||||
/// </summary>
|
||||
public UInt32 Hash
|
||||
public uint Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (hash == 0)
|
||||
{
|
||||
hash = to32BitNumber();
|
||||
hash = To32BitNumber();
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
|
@ -171,7 +179,7 @@ namespace Cosmos.HAL.Network
|
|||
PutByte(xChars, 12, bytes[4]);
|
||||
xChars[14] = ':';
|
||||
PutByte(xChars, 15, bytes[5]);
|
||||
return new String(xChars);
|
||||
return new string(xChars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Cosmos.System.Network.ARP
|
|||
/// <summary>
|
||||
/// Cache.
|
||||
/// </summary>
|
||||
private static Dictionary<uint, MACAddress> cache;
|
||||
public static Dictionary<uint, MACAddress> cache;
|
||||
|
||||
/// <summary>
|
||||
/// Ensure cache exists.
|
||||
|
|
@ -55,11 +55,7 @@ namespace Cosmos.System.Network.ARP
|
|||
internal static void Update(IPv4.Address ipAddress, MACAddress macAddress)
|
||||
{
|
||||
ensureCacheExists();
|
||||
if (ipAddress == null)
|
||||
{
|
||||
global::System.Console.Write("");
|
||||
}
|
||||
UInt32 ip_hash = ipAddress.Hash;
|
||||
uint ip_hash = ipAddress.Hash;
|
||||
if (ip_hash == 0)
|
||||
{
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace Cosmos.System.Network.Config
|
|||
/// <param name="config"></param>
|
||||
public static void Add(Address nameserver)
|
||||
{
|
||||
foreach (var ns in DNSNameservers)
|
||||
for (int i = 0; i < DNSNameservers.Count; i++)
|
||||
{
|
||||
if (ns.address.ToString() == nameserver.address.ToString())
|
||||
if (DNSNameservers[i].address.Equals(nameserver))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace Cosmos.System.Network.IPv4
|
|||
/// </summary>
|
||||
/// <param name="iphash">IP Hash.</param>
|
||||
/// <returns>ICMPClient</returns>
|
||||
internal static ICMPClient Client(uint iphash)
|
||||
internal static ICMPClient GetClient(uint iphash)
|
||||
{
|
||||
if (clients.ContainsKey(iphash) == true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace Cosmos.System.Network.IPv4.UDP.DNS
|
|||
{
|
||||
DNSPacket dns_packet = new DNSPacket(packetData);
|
||||
|
||||
DnsClient receiver = (DnsClient)UdpClient.Client(dns_packet.DestinationPort);
|
||||
DnsClient receiver = (DnsClient)UdpClient.GetClient(dns_packet.DestinationPort);
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.receiveData(dns_packet);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Cosmos.System.Network.IPv4
|
|||
switch (icmp_packet.ICMP_Type)
|
||||
{
|
||||
case 0:
|
||||
ICMPClient receiver = ICMPClient.Client(icmp_packet.SourceIP.Hash);
|
||||
ICMPClient receiver = ICMPClient.GetClient(icmp_packet.SourceIP.Hash);
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.receiveData(icmp_packet);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Cosmos.System.Network.IPv4.UDP
|
|||
return;
|
||||
}
|
||||
|
||||
UdpClient receiver = UdpClient.Client(udp_packet.DestinationPort);
|
||||
UdpClient receiver = UdpClient.GetClient(udp_packet.DestinationPort);
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.receiveData(udp_packet);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace Cosmos.System.Network.IPv4.UDP
|
|||
/// </summary>
|
||||
/// <param name="destPort">Destination port.</param>
|
||||
/// <returns>UdpClient</returns>
|
||||
internal static UdpClient Client(ushort destPort)
|
||||
internal static UdpClient GetClient(ushort destPort)
|
||||
{
|
||||
if (clients.ContainsKey((uint)destPort) == true)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue