Skip to content

Commit 47211a1

Browse files
authored
Fix calls address parameters (#76)
1 parent 7517a2f commit 47211a1

File tree

6 files changed

+20
-40
lines changed

6 files changed

+20
-40
lines changed

source/nanoFramework.System.Net/DNS.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress)
3939

4040
for (int i = 0; i < cAddresses; i++)
4141
{
42-
byte[] address = addresses[i];
43-
44-
SocketAddress sockAddress = new SocketAddress(address);
45-
46-
AddressFamily family;
47-
48-
//if(SystemInfo.IsBigEndian)
49-
////{
50-
// family = (AddressFamily)((address[0] << 8) | address[1]);
51-
//}
52-
//else
53-
{
54-
family = (AddressFamily)((address[1] << 8) | address[0]);
55-
}
56-
//port address[2-3]
57-
58-
if (family == AddressFamily.InterNetwork)
59-
{
60-
//This only works with IPv4 addresses
61-
62-
uint ipAddr = (uint)((address[7] << 24) | (address[6] << 16) | (address[5] << 8) | (address[4]));
63-
64-
ipAddresses[i] = new IPAddress((long)ipAddr);
65-
}
42+
ipAddresses[i] = new IPAddress(addresses[i]);
6643
}
6744

6845
ipHostEntry.hostName = canonicalName;

source/nanoFramework.System.Net/IPAddress.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ public IPAddress(long newAddress)
7575
/// <param name="address"></param>
7676
public IPAddress(byte[] address)
7777
{
78-
if (address.Length == IPv4AddressBytes)
78+
if (address[0] == (byte)AddressFamily.InterNetwork)
7979
{
8080
_family = AddressFamily.InterNetwork;
81-
_address = ((address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]) & 0x0FFFFFFFF);
81+
// need to offset address by 4 (1st are family, 2nd are port
82+
_address = ((address[3 + 4] << 24 | address[2 + 4] << 16 | address[1 + 4] << 8 | address[0 + 4]) & 0x0FFFFFFFF);
8283
}
83-
else
84+
else if (address[0] == (byte)AddressFamily.InterNetworkV6)
8485
{
8586
_family = AddressFamily.InterNetworkV6;
8687

@@ -89,6 +90,11 @@ public IPAddress(byte[] address)
8990
_numbers[i] = (ushort)(address[i * 2] * 256 + address[i * 2 + 1]);
9091
}
9192
}
93+
else
94+
{
95+
// unsupported address family
96+
throw new NotSupportedException();
97+
}
9298
}
9399

94100
/// <summary>

source/nanoFramework.System.Net/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
////////////////////////////////////////////////////////////////
1414
// update this whenever the native assembly signature changes //
15-
[assembly: AssemblyNativeVersion("1.1.0.0")]
15+
[assembly: AssemblyNativeVersion("1.1.1.0")]
1616
////////////////////////////////////////////////////////////////
1717

1818
// Setting ComVisible to false makes the types in this assembly not visible

source/nanoFramework.System.Net/Sockets/Socket.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,20 @@ private EndPoint GetEndPoint(bool fLocal)
123123
m_localEndPoint = new IPEndPoint(IPAddress.Any, 0);
124124
}
125125

126-
byte[] address = null;
126+
EndPoint endPoint = null;
127127

128128
if (fLocal)
129129
{
130-
NativeSocket.getsockname(this, out address);
130+
NativeSocket.getsockname(this, out endPoint);
131131
}
132132
else
133133
{
134-
NativeSocket.getpeername(this, out address);
134+
NativeSocket.getpeername(this, out endPoint);
135135
}
136136

137-
SocketAddress socketAddress = new SocketAddress(address);
138-
ep = m_localEndPoint.Create(socketAddress);
139-
140137
if (fLocal)
141138
{
142-
m_localEndPoint = ep;
139+
m_localEndPoint = endPoint;
143140
}
144141

145142
return ep;

source/nanoFramework.System.Net/Sockets/SocketsNative.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ internal class NativeSocket
4141
public static extern void shutdown(object socket, int how, out int err);
4242

4343
[MethodImpl(MethodImplOptions.InternalCall)]
44-
public static extern int sendto(object socket, byte[] buf, int offset, int count, int flags, int timeout_ms, EndPoint address);
44+
public static extern int sendto(object socket, byte[] buf, int offset, int count, int flags, int timeout_ms, EndPoint endPoint);
4545

4646
[MethodImpl(MethodImplOptions.InternalCall)]
47-
public static extern int recvfrom(object socket, byte[] buf, int offset, int count, int flags, int timeout_ms, ref EndPoint address);
47+
public static extern int recvfrom(object socket, byte[] buf, int offset, int count, int flags, int timeout_ms, ref EndPoint endPoint);
4848

4949
[MethodImpl(MethodImplOptions.InternalCall)]
50-
public static extern void getpeername(object socket, out byte[] address);
50+
public static extern void getpeername(object socket, out EndPoint endPoint);
5151

5252
[MethodImpl(MethodImplOptions.InternalCall)]
53-
public static extern void getsockname(object socket, out byte[] address);
53+
public static extern void getsockname(object socket, out EndPoint endPoint);
5454

5555
[MethodImpl(MethodImplOptions.InternalCall)]
5656
public static extern void getsockopt(object socket, int level, int optname, byte[] optval);

source/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.1.0-preview.{height}",
3+
"version": "1.1.1-preview.{height}",
44
"release": {
55
"branchName" : "release-v{version}",
66
"versionIncrement" : "minor",

0 commit comments

Comments
 (0)