internal static StringBuilder IPv6AddressToStringHelper(ushort[] address, uint scopeId) { const int INET6_ADDRSTRLEN = 65; StringBuilder buffer = StringBuilderCache.Acquire(INET6_ADDRSTRLEN); if (IPv6AddressHelper.ShouldHaveIpv4Embedded(address)) { // We need to treat the last 2 ushorts as a 4-byte IPv4 address, // so output the first 6 ushorts normally, followed by the IPv4 address. AppendSections(address, 0, 6, buffer); if (buffer[buffer.Length - 1] != ':') { buffer.Append(':'); } buffer.Append(IPAddressParser.IPv4AddressToString(ExtractIPv4Address(address))); } else { // No IPv4 address. Output all 8 sections as part of the IPv6 address // with normal formatting rules. AppendSections(address, 0, 8, buffer); } // If there's a scope ID, append it. if (scopeId != 0) { buffer.Append('%').Append(scopeId); } return(buffer); }
public static IPAddress Parse(string ipString) { if (ipString == null) { throw new ArgumentNullException(nameof(ipString)); } return(IPAddressParser.Parse(ipString.AsSpan(), tryParse: false)); }
/// <devdoc> /// <para> /// Converts the Internet address to either standard dotted quad format /// or standard IPv6 representation. /// </para> /// </devdoc> public override string ToString() { if (_toString == null) { _toString = IsIPv4 ? IPAddressParser.IPv4AddressToString(PrivateAddress) : IPAddressParser.IPv6AddressToString(_numbers, PrivateScopeId); } return(_toString); }
/// <devdoc> /// <para> /// Converts an IP address string to an <see cref='System.Net.IPAddress'/> instance. /// </para> /// </devdoc> public static bool TryParse(string ipString, out IPAddress address) { if (ipString == null) { address = null; return(false); } address = IPAddressParser.Parse(ipString.AsSpan(), tryParse: true); return(address != null); }
/// <devdoc> /// <para> /// Converts the Internet address to either standard dotted quad format /// or standard IPv6 representation. /// </para> /// </devdoc> public override string ToString() { if (_toString == null) { _toString = IsIPv4 ? IPAddressParser.IPv4AddressToString(GetAddressBytes()) : IPAddressParser.IPv6AddressToString(GetAddressBytes(), PrivateScopeId); } return(_toString); }
public static bool TryParse([NotNullWhen(true)] string?ipString, [NotNullWhen(true)] out IPAddress?address) { if (ipString == null) { address = null; return(false); } address = IPAddressParser.Parse(ipString.AsSpan(), tryParse: true); return(address != null); }
/// <devdoc> /// <para> /// Converts the Internet address to either standard dotted quad format /// or standard IPv6 representation. /// </para> /// </devdoc> public override string ToString() { if (StringRepresentation == null) { // IPv6 Changes: generate the IPV6 representation if (_family == AddressFamily.InterNetworkV6) { StringRepresentation = IPAddressParser.IPv6AddressToString(this.GetAddressBytes(), (UInt32)_scopeId); } else { StringRepresentation = IPAddressParser.IPv4AddressToString(this.GetAddressBytes()); } } return(StringRepresentation); }
public bool TryFormat(Span <char> destination, out int charsWritten) { return(IsIPv4 ? IPAddressParser.IPv4AddressToString(PrivateAddress, destination, out charsWritten) : IPAddressParser.IPv6AddressToString(_numbers, PrivateScopeId, destination, out charsWritten)); }
public static IPAddress Parse(ReadOnlySpan <char> ipSpan) { return(IPAddressParser.Parse(ipSpan, tryParse: false)); }
public static bool TryParse(ReadOnlySpan <char> ipSpan, out IPAddress address) { address = IPAddressParser.Parse(ipSpan, tryParse: true); return(address != null); }
public static IPAddress Parse(string ipString) { return(IPAddressParser.Parse(ipString, false)); }
/// <devdoc> /// <para> /// Converts an IP address string to an <see cref='System.Net.IPAddress'/> instance. /// </para> /// </devdoc> public static bool TryParse(string ipString, out IPAddress address) { address = IPAddressParser.Parse(ipString, true); return(address != null); }
/// <devdoc> /// <para> /// Converts the Internet address to either standard dotted quad format /// or standard IPv6 representation. /// </para> /// </devdoc> public override string ToString() => _toString ??= IsIPv4? IPAddressParser.IPv4AddressToString(PrivateAddress) : IPAddressParser.IPv6AddressToString(_numbers !, PrivateScopeId);
public static IPAddress Parse(string ipString) { ArgumentNullException.ThrowIfNull(ipString); return(IPAddressParser.Parse(ipString.AsSpan(), tryParse: false) !); }