1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd netbsd openbsd
14 type parseAddrsTest struct {
16 fn func(int, []byte) (int, Addr, error)
21 var parseAddrsLittleEndianTests = []parseAddrsTest{
23 sysRTA_DST | sysRTA_GATEWAY | sysRTA_NETMASK | sysRTA_BRD,
26 0x38, 0x12, 0x0, 0x0, 0xff, 0xff, 0xff, 0x0,
27 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
28 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
29 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
30 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
31 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
32 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
34 0x38, 0x12, 0x2, 0x0, 0x6, 0x3, 0x6, 0x0,
35 0x65, 0x6d, 0x31, 0x0, 0xc, 0x29, 0x66, 0x2c,
36 0xdc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
37 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
38 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
39 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
40 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
42 0x10, 0x2, 0x0, 0x0, 0xac, 0x10, 0xdc, 0xb4,
43 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
45 0x10, 0x2, 0x0, 0x0, 0xac, 0x10, 0xdc, 0xff,
46 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
50 &LinkAddr{Index: 2, Name: "em1", Addr: []byte{0x00, 0x0c, 0x29, 0x66, 0x2c, 0xdc}},
51 &Inet4Addr{IP: [4]byte{172, 16, 220, 180}},
56 &Inet4Addr{IP: [4]byte{172, 16, 220, 255}},
60 sysRTA_NETMASK | sysRTA_IFP | sysRTA_IFA,
63 0x7, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0x0,
65 0x18, 0x12, 0xa, 0x0, 0x87, 0x8, 0x0, 0x0,
66 0x76, 0x6c, 0x61, 0x6e, 0x35, 0x36, 0x38, 0x32,
67 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
69 0x10, 0x2, 0x0, 0x0, 0xa9, 0xfe, 0x0, 0x1,
70 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
75 &Inet4Addr{IP: [4]byte{255, 255, 255, 0}},
77 &LinkAddr{Index: 10, Name: "vlan5682"},
78 &Inet4Addr{IP: [4]byte{169, 254, 0, 1}},
85 func TestParseAddrs(t *testing.T) {
86 tests := parseAddrsLittleEndianTests
87 if nativeEndian != littleEndian {
88 t.Skip("no test for non-little endian machine yet")
91 for i, tt := range tests {
92 as, err := parseAddrs(tt.attrs, tt.fn, tt.b)
97 as = as[:8] // the list varies between operating systems
98 if !reflect.DeepEqual(as, tt.as) {
99 t.Errorf("#%d: got %+v; want %+v", i, as, tt.as)