Results 1 to 5 of 5

Thread: IPv6

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    IPv6

    I'm writing a class module to represent an IP address and it works fine for IPv4 addresses. But I'm wanting to support IPv6 addresses also. IPv6 addresses are 128 bits in size, and VB doesn't have a data type that can store a number that large.

    Is it possible to use 2 64-bit values (high and low)? If so, how?

    My IP class has a property to get the IP in decimal form (not dotted notation like "123.123.123.123") but just a plain integer.

    Would I need to make another class to store the 128-bit value and use that class as a return type for the property? Example:

    vb Code:
    1. Public Property Get IPAddressDecimal() As Large128BitIntegerClass
    2. '?
    3. End Property


  2. #2
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: IPv6

    Why not store the IPV6 number as an array of bytes? The problem goes away then.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: IPv6

    If an array of bytes or an array of 4 longs doesn't do the trick? You may consider using a function/sub vs a property.... rough example using longs, currency datatype may be a posibility too.
    Code:
    Public Function IPv6(Part1 As Long, Part2 As Long, Part3 As Long, Part4 As Long)
    
    End Function
    Another option... You can always have the property pass a pointer to a 128bit structure. The receiving end can use copymemory to transfer the data....
    Code:
     ' class
    Private Type IPv6Structure
        Part1 As Long
        Part2 As Long
        Part3 As Long
        Part4 As Long
    End Type
    Private m_Address As IPV6Structure
    
    Public Property Get IPV6Address() As Long
        IPV6Address = VarPtr(m_Address)
    End Type
    Last edited by LaVolpe; May 1st, 2009 at 02:46 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: IPv6

    Sorry for taking so long to reply...

    I have the IP address stored in an array of bytes. It's working good for IPv4 addresses.

    I want to store the IP numerically because it's faster to compare it to other IP addresses (like checking a ban list).

    I think I'll do a struct instead like LaVolpe's example, though. But can a Currency variable hold an IPv6 address? I was assuming it couldn't (64-bit).
    Last edited by DigiRev; May 8th, 2009 at 03:36 AM.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: IPv6

    Currency is 64 bits; so you'd need 2 currency variables.

    Regarding comparing byte arrays. You can use this API on NT based systems. Note that since memory pointers are used in the parameters, it can point to a byte array, long array, and other possible storage structures like UDTs for example.
    Code:
    Private Declare Function CompMemory Lib "ntdll.dll" Alias "RtlCompareMemory" _
    (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long) As Long
    
    ' example
    1   If CompareMemory(myIP6(0), banIP(0), 16&)=16& Then ' equal data
    2   If CompareMemory(myUDT, banUDT, 16&)=16& Then ' equal data
    ' assuming UDT is 4 longs, 2 currency, 8 Integers, or something else tallying 16 bytes
    Last edited by LaVolpe; May 8th, 2009 at 10:47 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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