|
-
Apr 30th, 2009, 08:19 PM
#1
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:
Public Property Get IPAddressDecimal() As Large128BitIntegerClass
'?
End Property
-
May 1st, 2009, 01:34 PM
#2
Frenzied Member
Re: IPv6
Why not store the IPV6 number as an array of bytes? The problem goes away then.
-
May 1st, 2009, 02:31 PM
#3
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.
-
May 7th, 2009, 09:53 PM
#4
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.
-
May 8th, 2009, 09:43 AM
#5
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.
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
|