internal static IpV4OptionTimestampAndAddress Read(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues) { if (numValues % 2 != 0) { return((IpV4OptionTimestampAndAddress)null); } IpV4OptionTimedAddress[] optionTimedAddressArray = new IpV4OptionTimedAddress[numValues / 2]; for (int index = 0; index != numValues / 2; ++index) { optionTimedAddressArray[index] = new IpV4OptionTimedAddress(ByteArrayExtensions.ReadIpV4Address(buffer, ref offset, Endianity.Big), ByteArrayExtensions.ReadIpV4TimeOfDay(buffer, ref offset, Endianity.Big)); } return(new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, optionTimedAddressArray)); }
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); } }
internal static bool TryRead(out IpV4Address[] addresses, out byte pointedAddressIndex, byte[] buffer, ref int offset, byte valueLength) { addresses = (IpV4Address[])null; pointedAddressIndex = (byte)0; if ((int)valueLength < 1 || (int)valueLength % 4 != 1) { return(false); } byte num = buffer[offset++]; if ((int)num % 4 != 0 || (int)num < 4) { return(false); } pointedAddressIndex = (byte)((int)num / 4 - 1); int length = (int)valueLength / 4; addresses = new IpV4Address[length]; for (int index = 0; index != length; ++index) { addresses[index] = ByteArrayExtensions.ReadIpV4Address(buffer, ref offset, Endianity.Big); } return(true); }
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))); }