namespace Minecraft.Server.FourKit.Net; /// /// Represents an IP Socket Address (IP address + port number). /// public class InetSocketAddress { private readonly InetAddress _address; private readonly string _hostname; private readonly int _port; /// /// Creates a socket address from an IP address and a port number. /// /// The IP address. /// The port number. public InetSocketAddress(InetAddress addr, int port) { _address = addr; _hostname = addr.getHostAddress(); _port = port; } /// /// Creates a socket address from a hostname and a port number. /// /// The hostname or IP address string. /// The port number. public InetSocketAddress(string hostname, int port) { _hostname = hostname ?? string.Empty; _address = new InetAddress(_hostname); _port = port; } /// /// Creates a socket address where the IP address is the wildcard address /// and the port number a specified value. /// /// The port number. public InetSocketAddress(int port) { _hostname = "0.0.0.0"; _address = new InetAddress(_hostname); _port = port; } /// /// Gets the InetAddress. /// /// The InetAddress. public InetAddress getAddress() => _address; /// /// Gets the hostname. /// /// The hostname, or the IP address string if created from an address. public string getHostName() => _hostname; /// /// Gets the port number. /// /// The port number. public int getPort() => _port; /// public override int GetHashCode() => HashCode.Combine(_hostname, _port); /// public override bool Equals(object? obj) { if (obj is InetSocketAddress other) return _hostname == other._hostname && _port == other._port; return false; } /// public override string ToString() => _hostname + ":" + _port; }