views:

121

answers:

1

I'd like to use System.Net.IPAddress.TryParse to validate IPv6 addresses because I don't want to write my own reg exp :-)

However, this seems to allow strings such as "(validIPv6)](anythingatallhere)" - for example, "1234::5678:abcd]whargarbl".

Is there a reason for these being valid, or is this a fault?

This is further complicated by the fact that I actually want only strings of the form "[(validIPv6)]:(portnumber)" so I'm going to have to do a bit of validation myself.

A: 

I was looking through reflector and it seems that if your current OS does not support IPV6 a parse routine is called that will ignore everything past the final ']' character.

This here seems to be the offending code, take notice of the second or condition as it relates to the preceding bit of code.

int length = ipString.Length;
fixed (char* str2 = ((char*) ipString))
{
    char* name = str2;
    if (IPv6AddressHelper.IsValid(name, start, ref length) || (length != ipString.Length))
ChaosPandion
Could you post a bit more? I can't really figure that out. Or do you not think the rest will help?Looks like IsValid either alters ipString (via str2 and name) or length... so either returns true if the whole string is valid, or alters the string/length if a substring is valid?
Rawling
@Rawling - Your theory is similar to what I gathered so posting more code probably wouldn't make a difference, it is really too much code to post anyway.
ChaosPandion
Also referenced here: http://social.msdn.microsoft.com/Forums/en/ncl/thread/52774eba-57ad-4232-bf2f-c804a0dcf8a4
Rawling
So basically, it's slightly broken. Having realised that I don't actually need to use a regulr expression, I'm tempted to just write my own validation code, either handling the square brackets myself and passing the rest to the library or just use Split and so on to validate it entirely myself.
Rawling