summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2021-01-07 01:15:20 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-07 01:17:10 -0800
commit776016ac6412006671a5dbccb5e9af21bf9b01f7 (patch)
treee0cdcaafec773ba8cfdcb8c69e63d058f506367a /test
parentfa8682da0fd43556ae0a405c02bac27e6d15a8e6 (diff)
Fix native benchmarks.
PiperOrigin-RevId: 350509137
Diffstat (limited to 'test')
-rw-r--r--test/benchmarks/harness/machine.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/test/benchmarks/harness/machine.go b/test/benchmarks/harness/machine.go
index 88e5e841b..405b646e8 100644
--- a/test/benchmarks/harness/machine.go
+++ b/test/benchmarks/harness/machine.go
@@ -16,6 +16,7 @@ package harness
import (
"context"
+ "errors"
"net"
"os/exec"
@@ -66,14 +67,19 @@ func (l *localMachine) RunCommand(cmd string, args ...string) (string, error) {
// IPAddress implements Machine.IPAddress.
func (l *localMachine) IPAddress() (net.IP, error) {
- conn, err := net.Dial("udp", "8.8.8.8:80")
+ addrs, err := net.InterfaceAddrs()
if err != nil {
- return nil, err
+ return net.IP{}, err
}
- defer conn.Close()
-
- addr := conn.LocalAddr().(*net.UDPAddr)
- return addr.IP, nil
+ for _, a := range addrs {
+ if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ return ipnet.IP, nil
+ }
+ }
+ }
+ // Unable to locate non-loopback address.
+ return nil, errors.New("no IPAddress available")
}
// CleanUp implements Machine.CleanUp and does nothing for localMachine.