sort_r is available on Macos and Freebsd, but actually the things are worse: it has different parameters order.
It seems to me that coding selection sort is more straightforward here than passing length to compare function in some other way or relying on fixed ipv4/ipv6 address lengths.
v3: - don't use qsort_r; - fix a couple of formatting inconsistencies.