MCPcopy Create free account
hub / github.com/pion/ice / TestLocalInterfaces_SkipLoopbackAddrs_WhenIncludeLoopbackFalse

Function TestLocalInterfaces_SkipLoopbackAddrs_WhenIncludeLoopbackFalse

net_test.go:143–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestLocalInterfaces_SkipLoopbackAddrs_WhenIncludeLoopbackFalse(t *testing.T) {
144 base, err := stdnet.NewNet()
145 require.NoError(t, err)
146
147 sysIfaces, err := base.Interfaces()
148 require.NoError(t, err)
149
150 var loop *transport.Interface
151 for _, ifc := range sysIfaces {
152 if ifc.Flags&net.FlagLoopback != 0 {
153 loop = ifc
154
155 break
156 }
157 }
158 if loop == nil {
159 t.Skip("no loopback interface found on this system")
160
161 return
162 }
163
164 // clone the loopback iface and clear the Loopback flag so the outer check
165 // doesn't drop it to force the inner `(ipAddr.IsLoopback() && !includeLoopback)`.
166 cloned := *loop
167 cloned.Flags |= net.FlagUp
168 cloned.Flags &^= net.FlagLoopback
169
170 wrapped := &fixedInterfacesNet{
171 Net: base,
172 list: []*transport.Interface{&cloned},
173 }
174
175 ifaces, addrs, ierr := localInterfaces(
176 wrapped,
177 nil, // interfaceFilter
178 nil, // ipFilter
179 nil, // networkTypes
180 false, // includeLoopback
181 )
182 require.NoError(t, ierr)
183
184 // don't assert on the number of interfaces because some systems may
185 // report the iface as having addresses in a way that causes it to be included.
186 // assert that all loopback addresses were skipped.
187 for _, a := range addrs {
188 require.False(t, a.addr.IsLoopback(), "loopback addresses must be skipped when includeLoopback=false")
189 }
190
191 _ = ifaces // intentionally don't assert on this, see above comment
192}
193
194// Captures ListenUDP attempts and always fails so the loop exhausts.
195type listenUDPCaptor struct {

Callers

nothing calls this directly

Calls 2

localInterfacesFunction · 0.85
InterfacesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…