Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions nanoFramework.System.Net/IPAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class IPAddress
/// This field is read-only.
/// </summary>
public static readonly IPAddress Any = new IPAddress(0x0000000000000000);

/// <summary>
/// Provides the IP loopback address. This field is read-only.
/// </summary>
Expand Down Expand Up @@ -75,23 +75,13 @@ public IPAddress(long newAddress)
/// <param name="address"></param>
public IPAddress(byte[] address)
{
if (address == null)
{
throw new ArgumentNullException();
}

if (address.Length != IPv4AddressBytes && address.Length != IPv6AddressBytes)
{
// unsupported address family
throw new NotSupportedException();
}

if (address.Length == IPv4AddressBytes)
if (address[0] == (byte)AddressFamily.InterNetwork)
{
_family = AddressFamily.InterNetwork;
Address = ((address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]) & 0x0FFFFFFFF);
// need to offset address by 4 (1st are family, 2nd are port
Address = ((address[3 + 4] << 24 | address[2 + 4] << 16 | address[1 + 4] << 8 | address[0 + 4]) & 0x0FFFFFFFF);
}
else
else if (address[0] == (byte)AddressFamily.InterNetworkV6)
{
_family = AddressFamily.InterNetworkV6;

Expand All @@ -100,6 +90,11 @@ public IPAddress(byte[] address)
_numbers[i] = (ushort)(address[i * 2] * 256 + address[i * 2 + 1]);
}
}
else
{
// unsupported address family
throw new NotSupportedException();
}
}

/// <summary>
Expand Down Expand Up @@ -193,8 +188,8 @@ internal IPAddress Snapshot()
case AddressFamily.InterNetwork:
return new IPAddress(Address);

//case AddressFamily.InterNetworkV6:
// return new IPAddress(m_Numbers, (uint)m_ScopeId);
//case AddressFamily.InterNetworkV6:
// return new IPAddress(m_Numbers, (uint)m_ScopeId);
}

throw new NotSupportedException();
Expand Down