diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-07 22:39:31 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-07 22:39:31 +0900 |
commit | d92b22f2c69b1ecdddbe2e3f477ae6551a51b9fb (patch) | |
tree | f23e73be8dee79cd3a9939809dee191dcc470a63 /server/sockopt.go | |
parent | beb39354e51eb74ab0a13d93dfde9e66e85d5bb6 (diff) |
server: set ttl to 1
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
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 +} |