Files
w3cjandClaude Opus 5.5 ae7c8b619f refactor(platform): parsePortRangeFirst and its test move to the linux files
Its only caller is ports_linux.go's ephemeralFirst, so on darwin
mise run deadcode listed it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 16:58:07 -07:00

29 lines
627 B
Go

package platform
import (
"os"
"strconv"
"strings"
)
// ephemeralFirst returns the first port of Linux's ephemeral range
// (net.ipv4.ip_local_port_range).
func ephemeralFirst() (int, bool) {
b, err := os.ReadFile("/proc/sys/net/ipv4/ip_local_port_range")
if err != nil {
return 0, false
}
return parsePortRangeFirst(string(b))
}
// parsePortRangeFirst reads the first field of Linux's
// ip_local_port_range ("32768\t60999").
func parsePortRangeFirst(s string) (int, bool) {
f := strings.Fields(s)
if len(f) == 0 {
return 0, false
}
n, err := strconv.Atoi(f[0])
return n, err == nil && n > 0 && n < 65536
}