Please extract this and the matching ipv6 confusion out into functions.