forked from mdlayher/netlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_linux_test.go
49 lines (43 loc) · 1.11 KB
/
message_linux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//+build linux
package netlink
import (
"syscall"
"testing"
"unsafe"
)
func TestHeaderMemoryLayoutLinux(t *testing.T) {
var nh Header
var sh syscall.NlMsghdr
if want, got := unsafe.Sizeof(sh), unsafe.Sizeof(nh); want != got {
t.Fatalf("unexpected structure sizes:\n- want: %v\n- got: %v",
want, got)
}
sh = syscall.NlMsghdr{
Len: 0x10101010,
Type: 0x2020,
Flags: 0x3030,
Seq: 0x40404040,
Pid: 0x50505050,
}
nh = sysToHeader(sh)
if want, got := sh.Len, nh.Length; want != got {
t.Fatalf("unexpected header length:\n- want: %v\n- got: %v",
want, got)
}
if want, got := sh.Type, uint16(nh.Type); want != got {
t.Fatalf("unexpected header type:\n- want: %v\n- got: %v",
want, got)
}
if want, got := sh.Flags, uint16(nh.Flags); want != got {
t.Fatalf("unexpected header flags:\n- want: %v\n- got: %v",
want, got)
}
if want, got := sh.Seq, nh.Sequence; want != got {
t.Fatalf("unexpected header sequence:\n- want: %v\n- got: %v",
want, got)
}
if want, got := sh.Pid, nh.PID; want != got {
t.Fatalf("unexpected header PID:\n- want: %v\n- got: %v",
want, got)
}
}