Ejemplo n.º 1
0
        public IPAddress(ReadOnlySpan <byte> address)
        {
            if (address.Length == IPAddressParserStatics.IPv4AddressBytes)
            {
                PrivateAddress = BinaryPrimitives.ReadUInt32LittleEndian(address);
            }
            else if (address.Length == IPAddressParserStatics.IPv6AddressBytes)
            {
                _numbers = new ushort[NumberOfLabels];

                for (int i = 0; i < NumberOfLabels; i++)
                {
                    _numbers[i] = (ushort)(address[i * 2] * 256 + address[i * 2 + 1]);
                }
            }
            else
            {
                throw new ArgumentException(SR.dns_bad_ip_address, nameof(address));
            }
        }
        public static void GetIPv6Address(ReadOnlySpan <byte> buffer, Span <byte> address, out uint scope)
        {
            buffer.Slice(8, address.Length).CopyTo(address);

            scope = BinaryPrimitives.ReadUInt32LittleEndian(buffer.Slice(24));
        }
 public static uint GetIPv4Address(ReadOnlySpan <byte> buffer)
 => BinaryPrimitives.ReadUInt32LittleEndian(buffer.Slice(4));