internal static DHCPv6RelayPacket FromByteArray(byte[] rawData, int offset) { DHCPv6PacketTypes type = (DHCPv6PacketTypes)rawData[offset]; offset += 1; Byte hopCount = rawData[offset]; offset += 1; IPv6Address linkAddress = IPv6Address.FromByteArray(rawData, offset); offset += 16; IPv6Address peerAddress = IPv6Address.FromByteArray(rawData, offset); offset += 16; List <DHCPv6PacketOption> options = new List <DHCPv6PacketOption>(); Byte[] innerPacketOptionValue = null; Int32 byteIndex = offset; while (byteIndex < rawData.Length) { UInt16 optionCode = ByteHelper.ConvertToUInt16FromByte(rawData, byteIndex); UInt16 length = ByteHelper.ConvertToUInt16FromByte(rawData, byteIndex + 2); Byte[] optionData = ByteHelper.CopyData(rawData, byteIndex, length + 4); if (optionCode == (Byte)DHCPv6PacketOptionTypes.RelayMessage) { innerPacketOptionValue = ByteHelper.CopyData(optionData, 4); } else { DHCPv6PacketOption suboption = DHCPv6PacketOptionFactory.GetOption(optionCode, optionData); options.Add(suboption); } byteIndex += 4 + length; } return(new DHCPv6RelayPacket( type, hopCount, linkAddress, peerAddress, options, DHCPv6Packet.FromByteArray(innerPacketOptionValue))); }
protected static DHCPv6Packet FromByteArray(Byte[] rawData) { DHCPv6PacketTypes type = (DHCPv6PacketTypes)rawData[0]; DHCPv6Packet result; if (type == DHCPv6PacketTypes.RELAY_REPL || type == DHCPv6PacketTypes.RELAY_FORW) { result = DHCPv6RelayPacket.FromByteArray(rawData, 0); } else { UInt32 transactionId = (UInt32)((rawData[1] << 16) | (rawData[2] << 8) | rawData[3]); result = new DHCPv6Packet( type, transactionId, DHCPv6PacketOptionFactory.GetOptions(rawData, 4)); } return(result); }