-
Notifications
You must be signed in to change notification settings - Fork 294
/
ipv4_windows_test.go
54 lines (45 loc) · 1.28 KB
/
ipv4_windows_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
package water
import (
"fmt"
"net"
"os/exec"
"strings"
"testing"
)
func startPing(t *testing.T, dst net.IP, _ bool) {
if err := exec.Command("ping", "-n", "4", dst.String()).Start(); err != nil {
t.Fatal(err)
}
}
func setupIfce(t *testing.T, ipNet net.IPNet, dev string) {
sargs := fmt.Sprintf("interface ip set address name=REPLACE_ME source=static addr=REPLACE_ME mask=REPLACE_ME gateway=none")
args := strings.Split(sargs, " ")
args[4] = fmt.Sprintf("name=%s", dev)
args[6] = fmt.Sprintf("addr=%s", ipNet.IP)
args[7] = fmt.Sprintf("mask=%d.%d.%d.%d", ipNet.Mask[0], ipNet.Mask[1], ipNet.Mask[2], ipNet.Mask[3])
cmd := exec.Command("netsh", args...)
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
}
func teardownIfce(t *testing.T, ifce *Interface) {
if err := ifce.Close(); err != nil {
t.Fatal(err)
}
}
func TestBroadcastTAP(t *testing.T) {
var (
self = net.IPv4(10, 0, 42, 1)
mask = net.IPv4Mask(255, 255, 255, 0)
brd = net.IPv4(10, 0, 42, 255)
)
ifce, err := New(Config{DeviceType: TAP})
if err != nil {
t.Fatalf("creating TAP error: %v\n", err)
}
defer teardownIfce(t, ifce)
dataCh, errCh := startRead(t, ifce)
setupIfce(t, net.IPNet{IP: self, Mask: mask}, ifce.Name())
startPing(t, brd, true)
waitForPingOrBust(t, true, true, self, brd, dataCh, errCh)
}