summaryrefslogtreecommitdiffhomepage
path: root/server/sockopt_linux_test.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-08-15 16:35:50 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-08-15 18:53:34 +0900
commit477b035bf4c053980f6e43cf446847a63d4bb010 (patch)
tree532077874f449a09ab2aa54f4b79b57a400a975b /server/sockopt_linux_test.go
parentd207ba5f69aa8ffe6ba772611fc8552d2ffb8cc5 (diff)
server: move linux specific functions to sockopt_linux.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/sockopt_linux_test.go')
-rw-r--r--server/sockopt_linux_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/server/sockopt_linux_test.go b/server/sockopt_linux_test.go
new file mode 100644
index 00000000..e3ef65d9
--- /dev/null
+++ b/server/sockopt_linux_test.go
@@ -0,0 +1,68 @@
+// Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// +build linux
+
+package server
+
+import (
+ "bytes"
+ "syscall"
+ "testing"
+ "unsafe"
+)
+
+func Test_buildTcpMD5Sig(t *testing.T) {
+ s, _ := buildTcpMD5Sig("1.2.3.4", "hello")
+
+ if unsafe.Sizeof(s) != 216 {
+ t.Error("TCPM5Sig struct size is wrong", unsafe.Sizeof(s))
+ }
+
+ buf1 := make([]uint8, 216)
+ p := unsafe.Pointer(&s)
+ src := uintptr(p)
+ for i := uintptr(0); i < 216; i++ {
+ buf1[i] = *(*byte)(unsafe.Pointer(src + i))
+ }
+
+ buf2 := []uint8{2, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+
+ if bytes.Compare(buf1, buf2) == 0 {
+ t.Log("OK")
+ } else {
+ t.Error("Something wrong v4")
+ }
+}
+
+func Test_buildTcpMD5Sigv6(t *testing.T) {
+ s, _ := buildTcpMD5Sig("fe80::4850:31ff:fe01:fc55", "helloworld")
+
+ buf1 := make([]uint8, 216)
+ p := unsafe.Pointer(&s)
+ src := uintptr(p)
+ for i := uintptr(0); i < 216; i++ {
+ buf1[i] = *(*byte)(unsafe.Pointer(src + i))
+ }
+
+ buf2 := []uint8{10, 0, 0, 0, 0, 0, 0, 0, 254, 128, 0, 0, 0, 0, 0, 0, 72, 80, 49, 255, 254, 1, 252, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 119, 111, 114, 108, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
+
+ buf2[0] = syscall.AF_INET6
+
+ if bytes.Compare(buf1, buf2) == 0 {
+ t.Log("OK")
+ } else {
+ t.Error("Something wrong v6")
+ }
+}