Close

Parse an IPV6 address

A project log for Silly software wishlist

Motivation to do some software projects by writing them down.

lion-mclionheadlion mclionhead 05/10/2020 at 07:430 Comments

IPV6 has been everywhere & nowhere for 20 years now, but for the lion kingdom's day jobs, it's already everywhere.  The problem is the shortpaw notation for the 16 byte addresses is a disaster.  After using it for a long time, lions have only started to intuitively recognize the :: to mean stuff with 0's until the left & right side of the :: are justified.  /128 represents the number of most significant bits comprising the subnet mask.

Despite some intuition, lions never type even the shortpaw notation but copy & paste all the addresses, so they might as well all be 8 hex numbers.  If IPV6 ever becomes manestream, most animals are going to write the addresses as 8 16 bit hex numbers.  The decision was made to provide a utility for converting the shortpaw notation to a full address.  

This is most useful for writing IPV6 software.  Linux has the getaddrinfo function which accepts shortpaw notated IPV6 addresses, but lions most often have to program embedded systems which require a full 16 byte address.

https://cdn.hackaday.io/files/1380505906331200/parseipv6.c

Let's parse some addresses.

% ./parseipv6 2017::7690:5000:0:2/64

2017:0000:0000:0000:7690:5000:0000:0002 prefix=64

% ./parseipv6 2017::

2017:0000:0000:0000:0000:0000:0000:0000 prefix=128

% ./parseipv6 ::ffff:0:0:0/96
0000:0000:0000:0000:ffff:0000:0000:0000 prefix=96

./parseipv6 2600:1:9a28:46f3:0:35:f8b4:f601/64
2600:0001:9a28:46f3:0000:0035:f8b4:f601 prefix=64

Despite so many decades of being just around the corner & supposedly allowing every device to have a fixed address, IPV6 addresses are still being assigned dynamically like the good old days.  

Discussions