Maximum length of the textual representation of an IPv6 address?
45 characters.
You might expect an address to be
0000:0000:0000:0000:0000:0000:0000:0000
8 * 4 + 7 = 39
8 groups of 4 digits with 7 :
between them.
But if you have an IPv4-mapped IPv6 address, the last two groups can be written in base 10 separated by .
, eg. [::ffff:192.168.100.228]
. Written out fully:
0000:0000:0000:0000:0000:ffff:192.168.100.228
(6 * 4 + 5) + 1 + (4 * 3 + 3) = 29 + 1 + 15 = 45
Note, this is an input/display convention - it's still a 128 bit address and for storage it would probably be best to standardise on the raw colon separated format, i.e. [0000:0000:0000:0000:0000:ffff:c0a8:64e4]
for the address above.
On Linux, see constant INET6_ADDRSTRLEN
(include <arpa/inet.h>
, see man inet_ntop
). On my system (header "in.h"):
#define INET6_ADDRSTRLEN 46
The last character is for terminating NULL, as I belive, so the max length is 45, as other answers.