Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
System.Net.IPAddress constructor
Message
 
To
19/02/2005 14:27:18
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00985599
Message ID:
00988648
Views:
55
Chris,
Thank you for the information. I figured I had to pass more that 4 bytes (IPv4), but I didn't find any information in the M$ docs about what I needed to pass. It does make sense to pass a byte array representing an IPv6 address since IPv4 will be history soon. Is there any easy way to translate from IPv4 to IPv6? If there is not then I guess translating from byte array to string and then using IPAddress.Parse() method isn't that bad, compared to converting to long.
I must agree with what the guy in the link you posted wrote, it is odd that I can't pass a 4 byte byte array in the IPAddress constructor.

Again thank you for the post and the information.

Sincerely,
Einar

>Einar,
>
>Sorry for skipping over the end of your original message. I hope the information I have now is helpful, or at least throws some light on the issue, if you haven't figured it out already.
>
>With framework version 1.1, passing a byte array to the IPAddress constructor will work if the array contains 16 bytes. This is because the array must represent an IPv6 address. See:
>
>http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-framework/9092/System-Net-IPAddress-constructor-still-not-fixed
>
>I put together the VB.NET test code below, which works. The 16-byte array represents the loopback address in IPv6 format.
>
>
>' Dim ba() As Byte = {127, 0, 0, 1} <-- Does not work
>
>Dim ba() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
>Dim IPTest As New IPAddress(ba)
>Dim IPBytes() As Byte = IPTest.GetAddressBytes()
>
>For IPByte As Integer = 0 To IPBytes.Length - 1
>   Console.WriteLine([String].Format("Address byte {0}: {1}", _
>      15 - IPByte, IPBytes(IPByte).ToString))
>Next
>
>Console.WriteLine([String].Format("Address is loopback: {0}", _
>   IPAddress.IsLoopback(IPTest).ToString))
>Console.ReadLine()
>
>
>>Chris,
>>That is what I had to do (see bottom of original message). The problem is that I receive the IP address in the form of a byte array and found it odd that I have to translate from a byte array into a string before I can create my IPAddress object.
>>
>>Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform