diff options
Diffstat (limited to 'server/sockopt.go')
-rw-r--r-- | server/sockopt.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/server/sockopt.go b/server/sockopt.go index 10b3c186..2392cdf4 100644 --- a/server/sockopt.go +++ b/server/sockopt.go @@ -2,6 +2,7 @@ package server import ( "net" + "strings" "syscall" "unsafe" ) @@ -43,3 +44,17 @@ func SetTcpMD5SigSockopts(fd int, address string, key string) error { uintptr(unsafe.Pointer(&t)), unsafe.Sizeof(t), 0) return e } + +func SetTcpTTLSockopts(conn *net.TCPConn, ttl int) error { + level := syscall.IPPROTO_IP + name := syscall.IP_TTL + if strings.Contains(conn.RemoteAddr().String(), "[") { + level = syscall.IPPROTO_IPV6 + name = syscall.IPV6_UNICAST_HOPS + } + file, _ := conn.File() + _, _, e := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(int(file.Fd())), + uintptr(level), uintptr(name), + uintptr(unsafe.Pointer(&ttl)), unsafe.Sizeof(ttl), 0) + return e +} |