Exemple #1
0
        public void FromByteArray_BooleanOption()
        {
            Random random                = new Random();
            UInt32 transactionId         = (UInt32)random.Next(0, 256 * 256 * 256);
            IPv6HeaderInformation header = new IPv6HeaderInformation(IPv6Address.FromString("fe80::1"), IPv6Address.FromString("fe80::2"));

            UInt16 firstIdentifier  = 4000;
            UInt16 secondIdentifier = 4002;

            DHCPv6Packet packet = new DHCPv6Packet(header, transactionId, DHCPv6PacketTypes.Solicit, new List <DHCPv6PacketOption>
            {
                new DHCPv6PacketBooleanOption(firstIdentifier, true),
                new DHCPv6PacketBooleanOption(secondIdentifier, false),
            }
                                                   );

            try
            {
                DHCPv6PacketOptionFactory.AddOptionType(firstIdentifier, (data) => DHCPv6PacketBooleanOption.FromByteArray(data, 0), true);
                DHCPv6PacketOptionFactory.AddOptionType(secondIdentifier, (data) => DHCPv6PacketBooleanOption.FromByteArray(data, 0), true);

                CheckByteRepresentation(packet, header);
            }
            finally
            {
                DHCPv6PacketOptionFactory.RemoveOptionType(firstIdentifier);
                DHCPv6PacketOptionFactory.RemoveOptionType(secondIdentifier);
            }
        }
Exemple #2
0
        public void FromByteArray_IPAddressOption()
        {
            Random random                = new Random();
            UInt32 transactionId         = (UInt32)random.Next(0, 256 * 256 * 256);
            IPv6HeaderInformation header = new IPv6HeaderInformation(IPv6Address.FromString("fe80::1"), IPv6Address.FromString("fe80::2"));

            UInt16 identifier = 6000;

            DHCPv6Packet packet = new DHCPv6Packet(header, transactionId, DHCPv6PacketTypes.Solicit, new List <DHCPv6PacketOption>
            {
                new DHCPv6PacketIPAddressOption(DHCPv6PacketOptionTypes.ServerUnicast, IPv6Address.FromString("fe80::1")),
                new DHCPv6PacketIPAddressOption(identifier, IPv6Address.FromString("fe80::2")),
            }
                                                   );

            try
            {
                DHCPv6PacketOptionFactory.AddOptionType(identifier, (data) => DHCPv6PacketIPAddressOption.FromByteArray(data, 0), true);

                CheckByteRepresentation(packet, header);
            }
            finally
            {
                DHCPv6PacketOptionFactory.RemoveOptionType(identifier);
            }
        }
Exemple #3
0
        public void FromByteArray_AddressListOption()
        {
            Random random                = new Random();
            UInt32 transactionId         = (UInt32)random.Next(0, 256 * 256 * 256);
            IPv6HeaderInformation header = new IPv6HeaderInformation(IPv6Address.FromString("fe80::1"), IPv6Address.FromString("fe80::2"));

            UInt16 firstIdentifier  = random.NextUInt16();
            UInt16 secondIdentifier = random.NextUInt16();

            DHCPv6PacketOptionFactory.AddOptionType(firstIdentifier, (data) => DHCPv6PacketIPAddressListOption.FromByteArray(data, 0), false);
            DHCPv6PacketOptionFactory.AddOptionType(secondIdentifier, (data) => DHCPv6PacketIPAddressListOption.FromByteArray(data, 0), false);

            DHCPv6Packet packet = new DHCPv6Packet(header, transactionId, DHCPv6PacketTypes.Solicit, new List <DHCPv6PacketOption>
            {
                new DHCPv6PacketIPAddressListOption(firstIdentifier, random.GetIPv6Addresses(2, 5)),
                new DHCPv6PacketIPAddressListOption(secondIdentifier, random.GetIPv6Addresses(2, 5)),
            }
                                                   );

            CheckByteRepresentation(packet, header);
        }