@@ -313,30 +313,41 @@ public struct ConnectionAddressData
313313 [ SerializeField ]
314314 public string ServerListenAddress ;
315315
316- private static NetworkEndpoint ParseNetworkEndpoint ( string ip , ushort port , bool silent = false )
316+ private static NetworkEndpoint ParseNetworkEndpoint ( string ip , ushort port )
317317 {
318318 NetworkEndpoint endpoint = default ;
319-
320- if ( ! NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv4 ) &&
321- ! NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv6 ) )
319+ if ( ! NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv4 ) )
322320 {
323- #if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
324- return default ;
325- #else // If the user does not have the most recent version of UnityTransport installed
326- if ( ! silent )
327- {
328- Debug . LogError ( $ "Invalid network endpoint: { ip } :{ port } .") ;
329- }
330- #endif
321+ NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv6 ) ;
331322 }
332-
333323 return endpoint ;
334324 }
335325
326+ private void InvalidEndpointError ( )
327+ {
328+ Debug . LogError ( $ "Invalid network endpoint: { Address } :{ Port } .") ;
329+ }
330+
336331 /// <summary>
337332 /// Endpoint (IP address and port) clients will connect to.
338333 /// </summary>
339- public NetworkEndpoint ServerEndPoint => ParseNetworkEndpoint ( Address , Port ) ;
334+ public NetworkEndpoint ServerEndPoint
335+ {
336+ get
337+ {
338+ var networkEndpoint = ParseNetworkEndpoint ( Address , Port ) ;
339+ if ( networkEndpoint == default )
340+ {
341+ #if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
342+ if ( ! IsValidFqdn ( Address ) )
343+ #endif
344+ {
345+ InvalidEndpointError ( ) ;
346+ }
347+ }
348+ return networkEndpoint ;
349+ }
350+ }
340351
341352 /// <summary>
342353 /// Endpoint (IP address and port) server will listen/bind on.
@@ -345,27 +356,35 @@ public NetworkEndpoint ListenEndPoint
345356 {
346357 get
347358 {
359+ NetworkEndpoint endpoint = default ;
348360 if ( string . IsNullOrEmpty ( ServerListenAddress ) )
349361 {
350- var ep = NetworkEndpoint . LoopbackIpv4 ;
362+ endpoint = NetworkEndpoint . LoopbackIpv4 ;
351363
352364 // If an address was entered and it's IPv6, switch to using ::1 as the
353365 // default listen address. (Otherwise we always assume IPv4.)
354366 if ( ! string . IsNullOrEmpty ( Address ) && ServerEndPoint . Family == NetworkFamily . Ipv6 )
355367 {
356- ep = NetworkEndpoint . LoopbackIpv6 ;
368+ endpoint = NetworkEndpoint . LoopbackIpv6 ;
357369 }
358-
359- return ep . WithPort ( Port ) ;
370+ endpoint = endpoint . WithPort ( Port ) ;
360371 }
361372 else
362373 {
363- return ParseNetworkEndpoint ( ServerListenAddress , Port ) ;
374+ endpoint = ParseNetworkEndpoint ( ServerListenAddress , Port ) ;
375+ if ( endpoint == default )
376+ {
377+ InvalidEndpointError ( ) ;
378+ }
364379 }
380+ return endpoint ;
365381 }
366382 }
367383
368- public bool IsIpv6 => ! string . IsNullOrEmpty ( Address ) && ParseNetworkEndpoint ( Address , Port , true ) . Family == NetworkFamily . Ipv6 ;
384+ /// <summary>
385+ /// Returns true if the end point address is of type <see cref="NetworkFamily.Ipv6"/>.
386+ /// </summary>
387+ public bool IsIpv6 => ! string . IsNullOrEmpty ( Address ) && NetworkEndpoint . TryParse ( Address , Port , out NetworkEndpoint _ , NetworkFamily . Ipv6 ) ;
369388 }
370389
371390
@@ -525,7 +544,7 @@ private NetworkPipeline SelectSendPipeline(NetworkDelivery delivery)
525544 }
526545
527546#if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
528- private bool IsValidFqdn ( string fqdn )
547+ private static IsValidFqdn ( string fqdn )
529548 {
530549 // Regular expression to validate FQDN
531550 string pattern = @"^(?=.{1,255}$)(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.(?!-)(?:[A-Za-z0-9-]{1,63}\.?)+[A-Za-z]{2,6}$" ;
0 commit comments