@@ -21,7 +21,7 @@ public class IPAddress
2121 /// This field is read-only.
2222 /// </summary>
2323 public static readonly IPAddress Any = new IPAddress ( 0x0000000000000000 ) ;
24-
24+
2525 /// <summary>
2626 /// Provides the IP loopback address. This field is read-only.
2727 /// </summary>
@@ -75,23 +75,13 @@ public IPAddress(long newAddress)
7575 /// <param name="address"></param>
7676 public IPAddress ( byte [ ] address )
7777 {
78- if ( address == null )
79- {
80- throw new ArgumentNullException ( ) ;
81- }
82-
83- if ( address . Length != IPv4AddressBytes && address . Length != IPv6AddressBytes )
84- {
85- // unsupported address family
86- throw new NotSupportedException ( ) ;
87- }
88-
89- if ( address . Length == IPv4AddressBytes )
78+ if ( address [ 0 ] == ( byte ) AddressFamily . InterNetwork )
9079 {
9180 _family = AddressFamily . InterNetwork ;
92- 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 ) ;
9383 }
94- else
84+ else if ( address [ 0 ] == ( byte ) AddressFamily . InterNetworkV6 )
9585 {
9686 _family = AddressFamily . InterNetworkV6 ;
9787
@@ -100,6 +90,11 @@ public IPAddress(byte[] address)
10090 _numbers [ i ] = ( ushort ) ( address [ i * 2 ] * 256 + address [ i * 2 + 1 ] ) ;
10191 }
10292 }
93+ else
94+ {
95+ // unsupported address family
96+ throw new NotSupportedException ( ) ;
97+ }
10398 }
10499
105100 /// <summary>
@@ -193,8 +188,8 @@ internal IPAddress Snapshot()
193188 case AddressFamily . InterNetwork :
194189 return new IPAddress ( Address ) ;
195190
196- //case AddressFamily.InterNetworkV6:
197- // return new IPAddress(m_Numbers, (uint)m_ScopeId);
191+ //case AddressFamily.InterNetworkV6:
192+ // return new IPAddress(m_Numbers, (uint)m_ScopeId);
198193 }
199194
200195 throw new NotSupportedException ( ) ;
0 commit comments