Instead of duplicating the whole function, just use an argument to specify is IPv6 is going to be used.