sing/common/control/bind_darwin.go
2022-09-14 12:52:34 +08:00

21 lines
522 B
Go

package control
import (
"syscall"
"golang.org/x/sys/unix"
)
func bindToInterface(conn syscall.RawConn, network string, address string, interfaceName string, interfaceIndex int) error {
if interfaceIndex == -1 {
return nil
}
return Raw(conn, func(fd uintptr) error {
switch network {
case "tcp6", "udp6":
return unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, interfaceIndex)
default:
return unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_BOUND_IF, interfaceIndex)
}
})
}