Results 1 to 4 of 4

Thread: IPAddress Class [RESOLVED]

  1. #1

    Thread Starter
    Lively Member BradBrening's Avatar
    Join Date
    Oct 2001
    Location
    Gillespie, IL
    Posts
    102

    Question 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

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    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)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member BradBrening's Avatar
    Join Date
    Oct 2001
    Location
    Gillespie, IL
    Posts
    102

    Re: IPAddress Class

    Cander;

    You are right - that is one heck of a hack! Works, though - many thanks!

    Brad

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Re: IPAddress Class [RESOLVED]

    You're welcome. I guess the IPAddress class must be a bit buggy.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width