Why is INET6_ADDRSTRLEN defined as 46 in C?
Because POSIX defines it to be 46:
INET6_ADDRSTRLEN
46. Length of the string form for IPv6.
While you are right that longtest IPv6 address takes 39 bytes, with IPv4 tunneling, the longest form can be 45 bytes:
ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255
And the 46th byte is for the terminating nul byte (in C a string). This explains how it came to be 46.