private static unsafe IPAddress CreateIPv6Address(ReadOnlySpan <byte> socketAddress)
        {
            Span <byte> address = stackalloc byte[IPAddressParserStatics.IPv6AddressBytes];
            uint        scope;

            SocketAddressPal.GetIPv6Address(socketAddress, address, out scope);

            return(new IPAddress(address, (long)scope));
        }
Пример #2
0
        internal IPAddress GetIPAddress()
        {
            if (Family == AddressFamily.InterNetworkV6)
            {
                Debug.Assert(Size >= IPv6AddressSize);

                byte[] address = new byte[IPAddressParser.IPv6AddressBytes];
                uint   scope;
                SocketAddressPal.GetIPv6Address(Buffer, address, out scope);

                return(new IPAddress(address, (long)scope));
            }
            else if (Family == AddressFamily.InterNetwork)
            {
                Debug.Assert(Size >= IPv4AddressSize);
                long address = (long)SocketAddressPal.GetIPv4Address(Buffer) & 0x0FFFFFFFF;
                return(new IPAddress(address));
            }
            else
            {
                throw new SocketException(SocketError.AddressFamilyNotSupported);
            }
        }