System.Uri and IPv6 with embedded IPv4
am 02.01.2008 14:00:00 von WilliamRandlett
The System.Uri class is not behaving as I expect when an IPv4 address is
embedded within an IPv6 address. The following test works fine, using IPv6
only:
[Test]
public void Uri_ShouldCreateValidUriFromSimpleIPv6Address()
{
Uri testUri = new Uri("http://[::1]:9050");
Assert.AreEqual(
"http://[0000:0000:0000:0000:0000:0000:0000:0001]:9050/",
testUri.ToString());
}
However, when I embed an IPv4 address, the Uri class begins converting the
address in a way that I do not expect:
public void Uri_ShouldCreateValidUriFromIPv4AddressEmbeddedWithinIPv6Add ress()
[Test]
{
Uri testUri = new Uri("http://[::101.45.75.219]:9050");
Assert.AreEqual(
"http://[0000:0000:0000:0000:0000:0000:101.45.75.219]:9050/" ,
testUri.ToString());
}
TestCase 'Uri_ShouldCreateValidUriFromIPv4AddressEmbeddedWithinIPv6Ad dress'
failed:
String lengths differ. Expected length=58, but was length=54.
Strings differ at index 38.
expected: <"...p://[0000:0000:0000:0000:0000:0000:101.45.75.219]:9050/">
but was: <"...p://[0000:0000:0000:0000:0000:0000:652D:4BDB]:9050/">
--------------------------------------------------^
Am I missing something here?
RE: System.Uri and IPv6 with embedded IPv4
am 05.01.2008 01:52:00 von WilliamRandlett
I have reposted this in the .NET Framework discusson board
(http://msdn.microsoft.com/newsgroups/managed/default.aspx?d g=microsoft.public.dotnet.framework&lang=en&cr=US)
"William Randlett" wrote:
> The System.Uri class is not behaving as I expect when an IPv4 address is
> embedded within an IPv6 address. The following test works fine, using IPv6
> only:
> [Test]
> public void Uri_ShouldCreateValidUriFromSimpleIPv6Address()
> {
> Uri testUri = new Uri("http://[::1]:9050");
> Assert.AreEqual(
> "http://[0000:0000:0000:0000:0000:0000:0000:0001]:9050/",
> testUri.ToString());
> }
>
> However, when I embed an IPv4 address, the Uri class begins converting the
> address in a way that I do not expect:
> public void Uri_ShouldCreateValidUriFromIPv4AddressEmbeddedWithinIPv6Add ress()
> [Test]
> {
> Uri testUri = new Uri("http://[::101.45.75.219]:9050");
> Assert.AreEqual(
> "http://[0000:0000:0000:0000:0000:0000:101.45.75.219]:9050/" ,
> testUri.ToString());
> }
> TestCase 'Uri_ShouldCreateValidUriFromIPv4AddressEmbeddedWithinIPv6Ad dress'
> failed:
> String lengths differ. Expected length=58, but was length=54.
> Strings differ at index 38.
> expected: <"...p://[0000:0000:0000:0000:0000:0000:101.45.75.219]:9050/">
> but was: <"...p://[0000:0000:0000:0000:0000:0000:652D:4BDB]:9050/">
> --------------------------------------------------^
>
> Am I missing something here?