From c7871a3ab2b542b37fb479bfe680cf44df4e0080 Mon Sep 17 00:00:00 2001 From: v2ray Date: Mon, 15 Aug 2016 21:33:32 +0200 Subject: [PATCH] test case for socket opt --- transport/internet/udp/hub_linux_test.go | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 transport/internet/udp/hub_linux_test.go diff --git a/transport/internet/udp/hub_linux_test.go b/transport/internet/udp/hub_linux_test.go new file mode 100644 index 00000000..590ea23d --- /dev/null +++ b/transport/internet/udp/hub_linux_test.go @@ -0,0 +1,41 @@ +// +build linux + +package udp_test + +import ( + "runtime" + "syscall" + "testing" + + "github.com/v2ray/v2ray-core/common/alloc" + v2net "github.com/v2ray/v2ray-core/common/net" + "github.com/v2ray/v2ray-core/proxy" + "github.com/v2ray/v2ray-core/testing/assert" + "github.com/v2ray/v2ray-core/transport/internet" + . "github.com/v2ray/v2ray-core/transport/internet/udp" +) + +func TestHubSocksOption(t *testing.T) { + assert := assert.On(t) + + hub, err := ListenUDP(v2net.LocalHostIP, v2net.Port(0), ListenOption{ + Callback: func(*alloc.Buffer, *proxy.SessionInfo) {}, + ReceiveOriginalDest: true, + }) + assert.Error(err).IsNil() + conn := hub.Connection() + + sysfd, ok := conn.(internet.SysFd) + assert.Bool(ok).IsTrue() + + fd, err := sysfd.SysFd() + assert.Error(err).IsNil() + + v, err := syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT) + assert.Error(err).IsNil() + assert.Int(v).Equals(1) + + v, err = syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR) + assert.Error(err).IsNil() + assert.Int(v).Equals(1) +}