// This file is provided under The MIT License as part of RiptideNetworking.
// Copyright (c) Tom Weiland
// For additional information please see the included LICENSE.md file or view it on GitHub:
// https://github.com/RiptideNetworking/Riptide/blob/main/LICENSE.md
using System.Net;
namespace Riptide.Utils
{
/// Contains extension methods for various classes.
public static class Extensions
{
/// Takes the 's IP address and port number and converts it to a string, accounting for whether the address is an IPv4 or IPv6 address.
/// A string containing the IP address and port number of the endpoint.
public static string ToStringBasedOnIPFormat(this IPEndPoint endPoint)
{
if (endPoint.Address.IsIPv4MappedToIPv6)
return $"{endPoint.Address.MapToIPv4()}:{endPoint.Port}";
return endPoint.ToString();
}
}
}