connection: implement IPv4/IPv6 (also with preference)

By default, we prefer IPv4 over IPv6; however, if the family
is PF_UNSPEC6, we prefer IPv6 over IPv4.