Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
 {
     if ((int)valueLength != 2)
     {
         return((Option)null);
     }
     return((Option) new IpV4OptionStreamIdentifier(ByteArrayExtensions.ReadUShort(buffer, ref offset, Endianity.Big)));
 }
 Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
 {
     if ((int)valueLength != 2)
     {
         return((Option)null);
     }
     return((Option) new TcpOptionMaximumSegmentSize(ByteArrayExtensions.ReadUShort(buffer, ref offset, Endianity.Big)));
 }
 Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
 {
     if ((int)valueLength != 10)
     {
         return((Option)null);
     }
     return((Option) new IpV4OptionTraceRoute(ByteArrayExtensions.ReadUShort(buffer, ref offset, Endianity.Big), ByteArrayExtensions.ReadUShort(buffer, ref offset, Endianity.Big), ByteArrayExtensions.ReadUShort(buffer, ref offset, Endianity.Big), ByteArrayExtensions.ReadIpV4Address(buffer, ref offset, Endianity.Big)));
 }
Exemplo n.º 4
0
        private static bool TryReadEntry(byte[] buffer, int payloadOffset, int payloadLength, GreSourceRouteEntryAddressFamily addressFamily, int offsetInPayload, out GreSourceRouteEntry entry)
        {
            entry = (GreSourceRouteEntry)null;
            switch (addressFamily)
            {
            case GreSourceRouteEntryAddressFamily.IpSourceRoute:
                if (offsetInPayload % 4 != 0 || payloadLength % 4 != 0)
                {
                    return(false);
                }
                int           length1   = payloadLength / 4;
                IpV4Address[] addresses = new IpV4Address[length1];
                for (int index = 0; index != length1; ++index)
                {
                    addresses[index] = ByteArrayExtensions.ReadIpV4Address(buffer, payloadOffset + index * 4, Endianity.Big);
                }
                entry = (GreSourceRouteEntry) new GreSourceRouteEntryIp(addresses, offsetInPayload / 4);
                return(true);

            case GreSourceRouteEntryAddressFamily.AsSourceRoute:
                if (offsetInPayload % 2 != 0 || payloadLength % 2 != 0)
                {
                    return(false);
                }
                int      length2   = payloadLength / 2;
                ushort[] asNumbers = new ushort[length2];
                for (int index = 0; index != length2; ++index)
                {
                    asNumbers[index] = ByteArrayExtensions.ReadUShort(buffer, payloadOffset + index * 2, Endianity.Big);
                }
                entry = (GreSourceRouteEntry) new GreSourceRouteEntryAs(asNumbers, offsetInPayload / 2);
                return(true);

            default:
                Datagram data = new Datagram(buffer, payloadOffset, payloadLength);
                entry = (GreSourceRouteEntry) new GreSourceRouteEntryUnknown(addressFamily, data, offsetInPayload);
                return(true);
            }
        }
Exemplo n.º 5
0
 internal IgmpGroupRecordDatagram(byte[] buffer, int offset)
     : base(buffer, offset, buffer.Length - offset < 8 ? buffer.Length - offset : Math.Min(buffer.Length - offset, 8 + 4 * (int)ByteArrayExtensions.ReadUShort(buffer, offset + 2, Endianity.Big) + 4 * (int)ByteArrayExtensions.ReadByte(buffer, offset + 1)))
 {
 }
Exemplo n.º 6
0
        internal static bool TryReadEntry(byte[] buffer, ref int offset, int length, out GreSourceRouteEntry entry)
        {
            entry = (GreSourceRouteEntry)null;
            if (length < 4)
            {
                return(false);
            }
            GreSourceRouteEntryAddressFamily addressFamily = (GreSourceRouteEntryAddressFamily)ByteArrayExtensions.ReadUShort(buffer, offset, Endianity.Big);
            byte num1 = buffer[offset + 3];

            if ((int)num1 == 0)
            {
                return(addressFamily == GreSourceRouteEntryAddressFamily.None);
            }
            if (4 + (int)num1 > length)
            {
                return(false);
            }
            byte num2 = buffer[offset + 2];

            if ((int)num2 > (int)num1 || !GreSourceRouteEntry.TryReadEntry(buffer, offset + 4, (int)num1, addressFamily, (int)num2, out entry))
            {
                return(false);
            }
            offset += entry.Length;
            return(true);
        }