On FreeBSD, the default ephemeral port range (10000-65535) overlaps with the test framework’s static port range (11000-26000), possibly causing intermittent “address already in use” failures when tests use dynamic port allocation (port=0).
This PR adds a helper that sets IP_PORTRANGE_HIGH via setsockopt() before binding, requesting ports from 49152-65535 instead, which avoids the overlap, as suggested in #34331 (comment) by @maflcko .
From FreeBSD’s sys/netinet/in.h:
0#define IP_PORTRANGE 19
1#define IP_PORTRANGE_HIGH 1
2#define IPPORT_EPHEMERALFIRST 10000 /* default range start */
3#define IPPORT_HIFIRSTAUTO 49152 /* high range start */
See also: FreeBSD https://man.freebsd.org/cgi/man.cgi?query=ip&sektion=4 man page.
I’ll leave the PR as a draft since I haven’t tested it on FreeBSD yet and would like to gather feedback on the approach.
Fixes #34331