|
-
May 11th, 2005, 12:07 PM
#1
Thread Starter
Lively Member
IPAddress Class [RESOLVED]
In VB6, I used to be able to create an IP address string from a long value by using the following statement/API call:
Code:
lpStr = inet_ntoa(lngAddress)
Then I would read the string from the pointer returned to get the IP address in dotted quad format.
I am trying to port this to VB.NET using the following code:
Code:
Dim oIP As New IPAddress(lngAddress)
strData = oIP.ToString
Usually this works, sometimes not. For example, if lngAddres = -156482353 (msn.com), I get the following exception: "Specified argument was out of the range of valid values."
Anyone have any idea what I may be doing wrong? The old API way returned the proper value = 207.68.172.246.
Brad
Last edited by BradBrening; May 11th, 2005 at 01:09 PM.
Reason: resolved
-
May 11th, 2005, 12:49 PM
#2
Re: IPAddress Class
This may seem kind of goofy but it was the only workaround I could find. I tried to pass the byte array created from the long in the first line, burt that just causes a completely useless error message "Additional Information: address". So this was all I could come up with
Code:
Dim b As Byte() = System.BitConverter.GetBytes(-156482353)
Dim ip As String
ip = b(0) & "." & b(1) & "." & b(2) & "." & b(3)
Dim a As System.Net.IPAddress = System.Net.IPAddress.Parse(ip)
-
May 11th, 2005, 01:08 PM
#3
Thread Starter
Lively Member
Re: IPAddress Class
Cander;
You are right - that is one heck of a hack! Works, though - many thanks!
Brad
-
May 11th, 2005, 01:15 PM
#4
Re: IPAddress Class [RESOLVED]
You're welcome. I guess the IPAddress class must be a bit buggy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|