Reputation: 140
I was searching an answer but I can't find it. I am using something like this
if (IPAddress.TryParse(val, out parsedOutput))
{
// ip address
parsedOk = true;
}
I am passing as val a string which looks like this: 0:0:0:0:0:0:1111:0
I am getting in parsedOutput this: ::17.17.0.0
Is there any way to get something like this: ::1111:0
instead of this "mixed" ipv4/ipv6 value?
Upvotes: 2
Views: 374
Reputation: 9978
The notation is actually correct according to RFC 5952 (A Recommendation for IPv6 Address Text Representation). In section 5 it says:
Addresses such as IPv4-Mapped IPv6 addresses, ISATAP [RFC5214], and IPv4-translatable addresses [ADDR-FORMAT] have IPv4 addresses embedded in the low-order 32 bits of the address. These addresses have a special representation that may mix hexadecimal and dot decimal notations. The decimal notation may be used only for the last 32 bits of the address. For these addresses, mixed notation is RECOMMENDED if the following condition is met: the address can be distinguished as having IPv4 addresses embedded in the lower 32 bits solely from the address field through the use of a well-known prefix. Such prefixes are defined in [RFC4291] and [RFC2765] at the time of this writing.
The IPv6 address you show is an IPv4-Compatible IPv6 Address. Its use is now deprecated, but it is still an IPv6 Address with Embedded IPv4 Addresses according to RFC 4291 section 2.5.5. The parsed output is therefore correct and recommended.
Upvotes: 4
Reputation: 495
Solution: It's the string you are trying to parse. IPv6 addresses must have something in the first portion of the address, so if you were to throw in something like 2000 in there like this: 2000:0:0:0:0:0:1111:0
it will parse it correctly. It has to do with the way IPv6 address are understood by the computer.
Upvotes: 0