mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
d4d652b455
- add shared netbind planning for strict tcp4/tcp6 bind semantics - support launcher/gateway host env overrides and launcher-to-gateway forwarding - cover host binding and forwarding with network and subprocess env tests
26 lines
501 B
Go
26 lines
501 B
Go
//go:build !windows
|
|
|
|
package netbind
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func applyIPv6OnlyControl(enabled bool) func(string, string, syscall.RawConn) error {
|
|
return func(_, _ string, rawConn syscall.RawConn) error {
|
|
var controlErr error
|
|
if err := rawConn.Control(func(fd uintptr) {
|
|
value := 0
|
|
if enabled {
|
|
value = 1
|
|
}
|
|
controlErr = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_V6ONLY, value)
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
return controlErr
|
|
}
|
|
}
|