MCPcopy
hub / github.com/perkeep/perkeep / loopbackIP

Function loopbackIP

internal/netutil/netutil.go:123–141  ·  view source on GitHub ↗

loopbackIP returns the first loopback IP address sniffing network interfaces or nil if none is found.

()

Source from the content-addressed store, hash-verified

121// loopbackIP returns the first loopback IP address sniffing network
122// interfaces or nil if none is found.
123func loopbackIP() net.IP {
124 interfaces, err := net.Interfaces()
125 if err != nil {
126 return nil
127 }
128 for _, inf := range interfaces {
129 const flagUpLoopback = net.FlagUp | net.FlagLoopback
130 if inf.Flags&flagUpLoopback == flagUpLoopback {
131 addrs, _ := inf.Addrs()
132 for _, addr := range addrs {
133 ip, _, err := net.ParseCIDR(addr.String())
134 if err == nil && ip.IsLoopback() {
135 return ip
136 }
137 }
138 }
139 }
140 return nil
141}
142
143// RandPort returns a random port to listen on.
144func RandPort() (int, error) {

Callers 2

BenchmarkLoopbackIPFunction · 0.85
LocalhostFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

BenchmarkLoopbackIPFunction · 0.68