MCPcopy Create free account
hub / github.com/cph6/zsync / getLocalIP

Function getLocalIP

t/zsync/integration_test.go:80–91  ·  view source on GitHub ↗

getLocalIP returns the local machine's IP address (excluding localhost) It tries to connect to a remote address to determine the local interface

()

Source from the content-addressed store, hash-verified

78// getLocalIP returns the local machine's IP address (excluding localhost)
79// It tries to connect to a remote address to determine the local interface
80func getLocalIP() string {
81 // Try to connect to a public DNS server to determine local interface
82 // This doesn't actually send any data, just determines which interface would be used
83 conn, err := net.Dial("udp", "8.8.8.8:80")
84 if err != nil {
85 return ""
86 }
87 defer conn.Close()
88
89 localAddr := conn.LocalAddr().(*net.UDPAddr)
90 return localAddr.IP.String()
91}
92
93func teardown() {
94 TeardownApacheServer()

Callers 1

setupFunction · 0.85

Calls 2

CloseMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected