| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics.CodeAnalysis; |
| | | 5 | | using System.Net.Sockets; |
| | | 6 | | |
| | | 7 | | namespace System.Net |
| | | 8 | | { |
| | | 9 | | public class DnsEndPoint : EndPoint |
| | | 10 | | { |
| | | 11 | | private readonly string _host; |
| | | 12 | | private readonly int _port; |
| | | 13 | | private readonly AddressFamily _family; |
| | | 14 | | |
| | 0 | 15 | | public DnsEndPoint(string host, int port) : this(host, port, AddressFamily.Unspecified) { } |
| | | 16 | | |
| | 0 | 17 | | public DnsEndPoint(string host, int port, AddressFamily addressFamily) |
| | 0 | 18 | | { |
| | 0 | 19 | | ArgumentException.ThrowIfNullOrEmpty(host); |
| | | 20 | | |
| | 0 | 21 | | ArgumentOutOfRangeException.ThrowIfLessThan(port, IPEndPoint.MinPort); |
| | 0 | 22 | | ArgumentOutOfRangeException.ThrowIfGreaterThan(port, IPEndPoint.MaxPort); |
| | | 23 | | |
| | 0 | 24 | | if (addressFamily != AddressFamily.InterNetwork && |
| | 0 | 25 | | addressFamily != AddressFamily.InterNetworkV6 && |
| | 0 | 26 | | addressFamily != AddressFamily.Unspecified) |
| | 0 | 27 | | { |
| | 0 | 28 | | throw new ArgumentException(SR.net_sockets_invalid_optionValue_all, nameof(addressFamily)); |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | _host = host; |
| | 0 | 32 | | _port = port; |
| | 0 | 33 | | _family = addressFamily; |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | public override bool Equals([NotNullWhen(true)] object? comparand) => |
| | 0 | 37 | | comparand is DnsEndPoint dnsComparand && |
| | 0 | 38 | | _family == dnsComparand._family && |
| | 0 | 39 | | _port == dnsComparand._port && |
| | 0 | 40 | | StringComparer.OrdinalIgnoreCase.Equals(_host, dnsComparand._host); |
| | | 41 | | |
| | | 42 | | public override int GetHashCode() => |
| | 0 | 43 | | HashCode.Combine( |
| | 0 | 44 | | (int)_family, |
| | 0 | 45 | | _port, |
| | 0 | 46 | | StringComparer.OrdinalIgnoreCase.GetHashCode(_host)); |
| | | 47 | | |
| | 0 | 48 | | public override string ToString() => $"{_family}/{_host}:{_port}"; |
| | | 49 | | |
| | 0 | 50 | | public string Host => _host; |
| | | 51 | | |
| | 0 | 52 | | public override AddressFamily AddressFamily => _family; |
| | | 53 | | |
| | 0 | 54 | | public int Port => _port; |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | |