github.com/sagernet/tfo-go@v0.0.0-20231209031829-7b5343ac1dc6/tfo_freebsd+linux.go (about)

     1  //go:build freebsd || linux
     2  
     3  package tfo
     4  
     5  import (
     6  	"syscall"
     7  
     8  	"golang.org/x/sys/unix"
     9  )
    10  
    11  func (*Dialer) socket(domain int) (int, error) {
    12  	return unix.Socket(domain, unix.SOCK_STREAM|unix.SOCK_NONBLOCK|unix.SOCK_CLOEXEC, unix.IPPROTO_TCP)
    13  }
    14  
    15  func (*Dialer) setIPv6Only(fd int, family int, ipv6only bool) error {
    16  	return setIPv6Only(fd, family, ipv6only)
    17  }
    18  
    19  const connectSyscallName = "sendmsg"
    20  
    21  func doConnect(fd uintptr, rsa syscall.Sockaddr, b []byte) (int, error) {
    22  	return syscall.SendmsgN(int(fd), b, nil, rsa, sendtoImplicitConnectFlag|unix.MSG_NOSIGNAL)
    23  }