@@ -252,30 +252,41 @@ public struct ConnectionAddressData
252252 [ SerializeField ]
253253 public string ServerListenAddress ;
254254
255- private static NetworkEndpoint ParseNetworkEndpoint ( string ip , ushort port , bool silent = false )
255+ private static NetworkEndpoint ParseNetworkEndpoint ( string ip , ushort port )
256256 {
257257 NetworkEndpoint endpoint = default ;
258-
259- if ( ! NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv4 ) &&
260- ! NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv6 ) )
258+ if ( ! NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv4 ) )
261259 {
262- #if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
263- return default ;
264- #else // If the user does not have the most recent version of UnityTransport installed
265- if ( ! silent )
266- {
267- Debug . LogError ( $ "Invalid network endpoint: { ip } :{ port } .") ;
268- }
269- #endif
260+ NetworkEndpoint . TryParse ( ip , port , out endpoint , NetworkFamily . Ipv6 ) ;
270261 }
271-
272262 return endpoint ;
273263 }
274264
265+ private void InvalidEndpointError ( )
266+ {
267+ Debug . LogError ( $ "Invalid network endpoint: { Address } :{ Port } .") ;
268+ }
269+
275270 /// <summary>
276271 /// Endpoint (IP address and port) clients will connect to.
277272 /// </summary>
278- public NetworkEndpoint ServerEndPoint => ParseNetworkEndpoint ( Address , Port ) ;
273+ public NetworkEndpoint ServerEndPoint
274+ {
275+ get
276+ {
277+ var networkEndpoint = ParseNetworkEndpoint ( Address , Port ) ;
278+ if ( networkEndpoint == default )
279+ {
280+ #if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
281+ if ( ! IsValidFqdn ( Address ) )
282+ #endif
283+ {
284+ InvalidEndpointError ( ) ;
285+ }
286+ }
287+ return networkEndpoint ;
288+ }
289+ }
279290
280291 /// <summary>
281292 /// Endpoint (IP address and port) server will listen/bind on.
@@ -284,30 +295,35 @@ public NetworkEndpoint ListenEndPoint
284295 {
285296 get
286297 {
298+ NetworkEndpoint endpoint = default ;
287299 if ( string . IsNullOrEmpty ( ServerListenAddress ) )
288300 {
289- var ep = NetworkEndpoint . LoopbackIpv4 ;
301+ endpoint = NetworkEndpoint . LoopbackIpv4 ;
290302
291303 // If an address was entered and it's IPv6, switch to using ::1 as the
292304 // default listen address. (Otherwise we always assume IPv4.)
293305 if ( ! string . IsNullOrEmpty ( Address ) && ServerEndPoint . Family == NetworkFamily . Ipv6 )
294306 {
295- ep = NetworkEndpoint . LoopbackIpv6 ;
307+ endpoint = NetworkEndpoint . LoopbackIpv6 ;
296308 }
297-
298- return ep . WithPort ( Port ) ;
309+ endpoint = endpoint . WithPort ( Port ) ;
299310 }
300311 else
301312 {
302- return ParseNetworkEndpoint ( ServerListenAddress , Port ) ;
313+ endpoint = ParseNetworkEndpoint ( ServerListenAddress , Port ) ;
314+ if ( endpoint == default )
315+ {
316+ InvalidEndpointError ( ) ;
317+ }
303318 }
319+ return endpoint ;
304320 }
305321 }
306322
307323 /// <summary>
308324 /// Returns true if the end point address is of type <see cref="NetworkFamily.Ipv6"/>.
309325 /// </summary>
310- public bool IsIpv6 => ! string . IsNullOrEmpty ( Address ) && ParseNetworkEndpoint ( Address , Port , true ) . Family == NetworkFamily . Ipv6 ;
326+ public bool IsIpv6 => ! string . IsNullOrEmpty ( Address ) && NetworkEndpoint . TryParse ( Address , Port , out NetworkEndpoint _ , NetworkFamily . Ipv6 ) ;
311327 }
312328
313329
@@ -494,7 +510,7 @@ private NetworkPipeline SelectSendPipeline(NetworkDelivery delivery)
494510 }
495511 }
496512#if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
497- private bool IsValidFqdn ( string fqdn )
513+ private static bool IsValidFqdn ( string fqdn )
498514 {
499515 // Regular expression to validate FQDN
500516 string pattern = @"^(?=.{1,255}$)(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.(?!-)(?:[A-Za-z0-9-]{1,63}\.?)+[A-Za-z]{2,6}$" ;
0 commit comments