コード例 #1
0
 internal DHCPv6RelayPacket(
     DHCPv6PacketTypes type,
     Byte hopCount,
     IPv6Address linkAddress, IPv6Address peerAddress,
     IEnumerable <DHCPv6PacketOption> options,
     DHCPv6Packet innerPacket) : base(type, options)
 {
     HopCount    = hopCount;
     LinkAddress = linkAddress;
     PeerAddress = peerAddress;
     InnerPacket = innerPacket;
 }
コード例 #2
0
 public static DHCPv6RelayPacket AsInnerRelay(
     Boolean isForward,
     Byte hopCount,
     IPv6Address linkAddress, IPv6Address peerAddress,
     IEnumerable <DHCPv6PacketOption> options,
     DHCPv6Packet innerPacket
     ) => new DHCPv6RelayPacket(
     isForward == true ? DHCPv6PacketTypes.RELAY_FORW : DHCPv6PacketTypes.RELAY_REPL,
     hopCount,
     linkAddress,
     peerAddress,
     options,
     innerPacket
     );
コード例 #3
0
        internal static DHCPv6RelayPacket ConstructRelayPacket(DHCPv6RelayPacket receivedPacket, DHCPv6Packet innerResponse)
        {
            DHCPv6Packet innerPacket = innerResponse;
            Byte         hopCount    = GetRelayPacketNumber(receivedPacket);

            if (receivedPacket.InnerPacket is DHCPv6RelayPacket packet)
            {
                innerPacket = ConstructRelayPacket(packet, innerResponse);
            }

            DHCPv6RelayPacket responsePacket = new DHCPv6RelayPacket(DHCPv6PacketTypes.RELAY_REPL,
                                                                     hopCount, receivedPacket.LinkAddress, receivedPacket.PeerAddress, receivedPacket.Options.ToList(), innerPacket);

            return(responsePacket);
        }
コード例 #4
0
        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)));
        }