golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.58k stars 17.41k forks source link

proposal: net: export supportsIPv4, supportsIPv6, supportsIPv4map #67991

Open database64128 opened 1 month ago

database64128 commented 1 month ago

Proposal Details

The net package queries and caches the capabilities of the system IP stack, and calls these functions to determine the type of socket to open when user code calls Dial, Listen and friends. It'd be nice if user code that opens sockets by hand can conveniently call these existing functions, instead of having to duplicate the feature in user code, or resorting to linkname.

The proposal is to add the following:

// SupportsIPv4 reports whether the platform supports IPv4 networking
// functionality.
func SupportsIPv4() bool

// SupportsIPv6 reports whether the platform supports IPv6 networking
// functionality.
func SupportsIPv6() bool

// SupportsIPv4map reports whether the platform supports mapping an
// IPv4 address inside an IPv6 address at transport layer
// protocols. See RFC 4291, RFC 4038 and RFC 3493.
func SupportsIPv4map() bool

This proposal, if accepted, will allow tfo-go to drop its linkname against net.favoriteAddrFamily.

For https://github.com/golang/go/issues/67401#issuecomment-2123749727.

xiaokentrl commented 1 month ago

Very Very Very good