File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
Source/NETworkManager.Models/Network Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,7 @@ private static IPAddress DetectLocalIPAddressFromRouting(IPAddress remoteIPAddre
231231
232232 if ( socket . LocalEndPoint is IPEndPoint ipAddress )
233233 return ipAddress . Address ;
234- }
234+ }
235235 catch ( SocketException ) { }
236236
237237 return null ;
@@ -296,20 +296,18 @@ public static IPAddress DetectLocalIPAddressFromNetworkInterface(AddressFamily a
296296 {
297297 // First try to get global or unique local addresses
298298 foreach ( var networkInterface in networkInterfaces )
299- {
300299 candidates . AddRange ( networkInterface . IPv6Address ) ;
301- }
302300
303301 // Return first candidate if any found
304302 if ( candidates . Count != 0 )
305303 return candidates . First ( ) ;
306304
307305 // Fallback to link-local addresses
308- foreach ( var networkInterface in networkInterfaces )
309- {
310- if ( networkInterface . IPv6AddressLinkLocal . Length != 0 )
311- return networkInterface . IPv6AddressLinkLocal . First ( ) ;
312- }
306+ var firstWithLinkLocal = networkInterfaces
307+ . FirstOrDefault ( ni => ni . IPv6AddressLinkLocal . Length != 0 ) ;
308+
309+ if ( firstWithLinkLocal != null )
310+ return firstWithLinkLocal . IPv6AddressLinkLocal . First ( ) ;
313311 }
314312
315313 return null ;
You can’t perform that action at this time.
0 commit comments