IPv6 Netowrk Device Numbering BP

Owen DeLong owen at delong.com
Thu Nov 1 14:07:35 UTC 2012


On Nov 1, 2012, at 06:06 , Nick Hilliard <nick at foobar.org> wrote:

> On 01/11/2012 12:20, Masataka Ohta wrote:
>> We should better introduce partially decimal format for
>> IPv6 addresses or, better, avoid IPv6 entirely.
> 
> No we shouldn't.  Text representations of IPv6 addresses are already a
> complete pain to parse.  We don't need to add to this pain by adding a new
> format which gains us nothing in particular over existing schemas such as
> that suggested by Eugeniu.
> 
> Nick
> 


I agree with you that we shouldn't introduce partially decimal format, but I
don't see why you say IPv6 addresses are difficult to parse.

1.	Tokenize (on : boundaries).
2.	If n(tokens) < 8, expand null token to 9-n tokens.
	(result 8 total tokens).
3.	Parse tokens left to right as 16 bit hex numbers, such that accumulator a accumulates each token t
	as follows:

	a<<=16
	a |= t

The only exceptions to this parsing would be if someone handed you a textual representation of
an IPv4 mapped address (::ffff:192.0.2.50), which essentially represents the partial decimal format
Masataka is requesting.

You really shouldn't need to parse these and it's perfectly valid to reject them as invalid input.
This really is an output only format to describe an IPv4 connection being mapped to an IPv6
socket with IPV6_V6ONLY=false in the socket options. These addresses should never appear
on the wire. Internally, the software sees them as any other 128 bit integer and only the
UI presentation of these numbers for display should ever use that format.

That format is used as a convenience for user display because it allows the user to readily
identify the IPv4 address of the connection rather than having to convert the hex to decimal
to know what host is involved.

Finally, at this point, if you're feeling like you have to write your own IP address parser,
you're probably doing something wrong. PLEASE PLEASE PLEASE use the standard
libraries whenever possible. inet_pton, getaddrinfo, etc. if you are using C. In PERL,
you have these, plus Net::IP as well which provides extensive IP address parsing and
manipulation capabilities.

There are similar library functions for virtually every other language at this point as well.

Owen





More information about the NANOG mailing list