-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnic_test.go
56 lines (46 loc) · 1.06 KB
/
nic_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
50
51
52
53
54
55
56
package packet
import (
"fmt"
"net"
"testing"
)
func TestLogic(t *testing.T) {
fmt.Println("Hello, playground")
ip := net.IPv4(192, 168, 1, 130)
n := net.IPNet{IP: net.IPv4(192, 168, 1, 129), Mask: net.IPv4Mask(255, 255, 255, 0)}
if !n.Contains(ip) {
t.Error("does not contain")
}
ip1 := net.ParseIP("192.168.0.1")
if !ip1.Equal(net.IPv4(192, 168, 0, 1)) {
t.Error("invalid ip match")
}
buf := []byte{192, 168, 0, 1}
if !ip1.To4().Equal(net.ParseIP("192.168.0.1")) {
t.Error("invalid ip match to4")
}
if !net.IP(buf).Equal(net.ParseIP("192.168.0.1")) {
t.Error("invalid ip match 3")
}
}
var ip4Test net.IP
func BenchmarkIPv6Allocation(t *testing.B) {
for i := 0; i < t.N; i++ {
buf := []byte{192, 168, 0, byte(i)}
ip4Test = func(ip net.IP) net.IP {
if ip.To4() != nil {
return ip
}
ip = ip.To16()
return ip
}(net.IP(buf))
}
}
func TestGetLinuxDefaultGateway(t *testing.T) {
ip, err := GetLinuxDefaultGateway()
if err != nil {
t.Errorf("GetLinuxDefaultGateway() error = %v", err)
return
}
fmt.Println("defaul gw", ip)
}