| 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. |
| 4 |
|
| 5 |
//go:build darwin || dragonfly || freebsd || netbsd || openbsd |
| 6 |
|
| 7 |
package routebsd |
| 8 |
|
| 9 |
import ( |
| 10 |
"syscall" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
func TestFetchRIBMessages(t *testing.T) { |
| 15 |
for _, typ := range []int{syscall.NET_RT_DUMP, syscall.NET_RT_IFLIST} { |
| 16 |
ms, err := FetchRIBMessages(typ, 0) |
| 17 |
if err != nil { |
| 18 |
t.Error(typ, err) |
| 19 |
continue |
| 20 |
} |
| 21 |
ss, err := msgs(ms).validate() |
| 22 |
if err != nil { |
| 23 |
t.Error(typ, err) |
| 24 |
continue |
| 25 |
} |
| 26 |
for _, s := range ss { |
| 27 |
t.Log(typ, s) |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
func TestParseRIBWithFuzz(t *testing.T) { |
| 33 |
for _, fuzz := range []string{ |
| 34 |
"0\x00\x05\x050000000000000000" + |
| 35 |
"00000000000000000000" + |
| 36 |
"00000000000000000000" + |
| 37 |
"00000000000000000000" + |
| 38 |
"0000000000000\x02000000" + |
| 39 |
"00000000", |
| 40 |
"\x02\x00\x05\f0000000000000000" + |
| 41 |
"0\x0200000000000000", |
| 42 |
"\x02\x00\x05\x100000000000000\x1200" + |
| 43 |
"0\x00\xff\x00", |
| 44 |
"\x02\x00\x05\f0000000000000000" + |
| 45 |
"0\x12000\x00\x02\x0000", |
| 46 |
"\x00\x00\x00\x01\x00", |
| 47 |
"00000", |
| 48 |
} { |
| 49 |
parseRIB([]byte(fuzz)) |
| 50 |
} |
| 51 |
} |