|Subject:||Re: working with numeric IP addresses in IPv6 and IPv4 forms|
|Posted by:||Remy Lebeau \(Indy Team\) (re…@lebeausoftware.org)|
|Date:||Wed, 9 Feb 2011|
"jvlad" <dm…@yandex.ru> wrote in message
> 1) it looks like IsIP is an ipv4-only function, shouldn't it be updated
> to support IPv6 too?
> or be renamed to reflect the fact that it supports ipv4 only?
If you are referring to the TIdStack.IsIP() method, then yes, it currently
supports IPv4 addresses only. I have added an item to our TODO list to
support IPv6 addresses.
In the meantime, there is a separate IsValidIP() function in the
IdGlobalProtocols unit that already supports IPv4 and IPv6, and there are
several individual IPv4 and IPv6 parsing functions in the IdGlobal unit.
> In latter case, what's the best way to check whether given string
> contains an IP address in numeric form?
You can use the IsValidIP() function, or alternatively the TIdIPAddress
class, whose MakeAddressObject() method will return a TIdIPAddress object if
the input string represents an IPv4 or IPv6 address. You can then use the
TIdIPAddress.AddrType property to know which one.
> I tried ping6 fe80::5efe:192.168.2.1%2 and it worked fine, so it is a
> correct IPv6 address,
> It looks like MakeCanonicalIPv6Address considers the scope (%2 in the
> case) as an invalid input and returns empty string in this case
Indy does not support or use Scope IDs at this time. They need to be
stripped off prior to parsing.
> even without a scope the returning value is wrong -- see p4 below
> 3) What's the most correct way to parse an address in the user input? For
> example one may enter an IPv4, IPv6 or a hostname. I'm not sure how to
> distinguish the tree cases in Indy.
There are quite a few options available: IsValidIP(),
TIdIPAddress.MakeAddressObject(), IPv4ToDWord(), MakeCanonicalIPv4Address(),
> 4) MakeCanonicalIPv6Address('fe80::5efe:192.168.2.1') returns
> 'FE80:0:0:0:5EFE:C0A8:0201' while in fact correct address would
> be 'FE80:0:0:0:0:5EFE:C0A8:0201'
> (see one more zero in the middle)
I have reproduced it and it will be fixed shortly, thanks.
> 5) regarding the scope in the address -- I think it's an important part
> and may improve performance.
It has been added to the TODO list for later review.
Remy Lebeau (TeamB)
working with numeric IP addresses in IPv6 and IPv4 forms posted by jvlad on Wed, 9 Feb 2011