Example #1
0
        public static DhcpClientIdentifier CreateFromRaw(byte[] rawData)
        {
            var address = new HardwareAddress((HardwareAddressType)rawData[0],
                                              rawData.Skip(1).ToArray());

            return(new DhcpClientIdentifier(address));
        }
Example #2
0
        public void RawAcknowledgePacket()
        {
            DHCPPacketBase p = DHCPPacketFactory.Read(RawData.Acknowledge);

            Assert.IsType(typeof(DHCPPacketBootReply), p);

            IPv4Address expectedClientIP = new IPv4Address(new byte[] { 0, 0, 0, 0 });
            IPv4Address expectedYourIP   = new IPv4Address(new byte[] { 192, 168, 0, 10 });
            IPv4Address expectedServerIP = new IPv4Address(new byte[] { 0, 0, 0, 0 });
            IPv4Address expectedRelayIP  = new IPv4Address(new byte[] { 0, 0, 0, 0 });

            Assert.True(EHardwareType.Ethernet == p.HardwareAddressType, "Address type wasn't Ethernet");
            Assert.True(6 == p.HardwareAddressLength, "Address length wasn't 6");
            Assert.True(0 == p.Hops, "Hops wasn't 0");
            Assert.True((uint)0x3d1e == p.TransactionID, string.Format("Transaction id was '{0:x}'", p.TransactionID));
            Assert.True(6 == p.HardwareAddressLength, "Address length wasn't 6");
            Assert.True(0 == p.Seconds, "Seconds wasn't 0");
            Assert.True(0 == p.Flags, "Flags wasn't 0");
            Assert.Equal(expectedClientIP.ToString(), p.ClientAddress.ToString());
            Assert.Equal(expectedYourIP.ToString(), p.YourAddress.ToString());
            Assert.Equal(expectedServerIP.ToString(), p.ServerAddress.ToString());
            Assert.Equal(expectedRelayIP.ToString(), p.RelayAgentAddress.ToString());

            HardwareAddress expectedHardwareAddress =
                new HardwareAddress(new MacAddress(new byte[] { 0x00, 0x0b, 0x82, 0x01, 0xfc, 0x42 }));

            byte[] expectedMac = expectedHardwareAddress.Address;
            byte[] actualMac   = p.ClientHardwareAddress.Address;

            for (int i = 0; i < expectedMac.Length; i++)
            {
                byte expected = expectedMac[i];
                byte actual   = actualMac[i];

                Assert.True(
                    expected == actual,
                    string.Format(
                        "Expected: '0x{0:x2}', Actual: '0x{1:x2}' at offset {2}. Expected: {3} Actual: {4}",
                        (byte)expected,
                        (byte)actual,
                        i,
                        expectedHardwareAddress,
                        p.ClientHardwareAddress));
            }

            Assert.Equal(new byte[64], p.ServerHostName);
            Assert.Equal(new byte[128], p.File);
        }
Example #3
0
        public void Raw()
        {
            HardwareAddress ha = new HardwareAddress(new MacAddress(new byte[] { 00, 11, 22, 33, 44, 55 }));

            IPv4Address expectedIP = new IPv4Address(new byte[] { 1, 2, 3, 4 });

            DHCPPacketBase p = new DHCPPacketBootRequest()
            {
                HardwareAddressType = EHardwareType.Ethernet,
                Hops                  = 99,
                TransactionID         = 0x12345678,
                Seconds               = 0xf00f,
                Flags                 = 0,
                ClientAddress         = expectedIP,
                YourAddress           = expectedIP,
                ServerAddress         = expectedIP,
                RelayAgentAddress     = expectedIP,
                ClientHardwareAddress = ha,
                ServerHostName        = new byte[64],
                File                  = new byte[128],
            };

            p.Options = new List <Option>()
            {
                new OptionEnd()
            };

            Assert.Equal(EHardwareType.Ethernet, p.HardwareAddressType);
            Assert.Equal(99, p.Hops);
            Assert.Equal((uint)0x12345678, p.TransactionID);
            Assert.Equal((ushort)0xf00f, p.Seconds);
            Assert.Equal((ushort)0, p.Flags);
            Assert.Equal(expectedIP.ToString(), p.ClientAddress.ToString());
            Assert.Equal(expectedIP.ToString(), p.YourAddress.ToString());
            Assert.Equal(expectedIP.ToString(), p.ServerAddress.ToString());
            Assert.Equal(expectedIP.ToString(), p.RelayAgentAddress.ToString());
            Assert.Equal(ha.Address, p.ClientHardwareAddress.Address);
            Assert.Equal(new byte[64], p.ServerHostName);
            Assert.Equal(new byte[128], p.File);

            Assert.Equal(265, p.GetRawBytes().Length);
        }
        private void ReadInitialValues()
        {
            LowpanIdentity   = new LowpanIdentity(wpanApi);
            LowpanCredential = new LowpanCredential(wpanApi);
            LowpanScanner    = new LowpanScanner(wpanApi);

            ncpVersion            = wpanApi.GetPropNcpVersion();
            protocolVersion       = wpanApi.GetPropProtocolVersion();
            interfaceType         = (SpinelProtocolType)wpanApi.GetPropInterfaceType();
            vendor                = wpanApi.GetPropVendorId().ToString();
            capabilities          = wpanApi.GetPropCaps();
            supportedChannels     = wpanApi.GetPhyChanSupported();
            networkInterfaceState = wpanApi.GetNetIfUp();
            threadStackState      = wpanApi.GetNetStackUp();
            netRole               = (SpinelNetRole)wpanApi.GetNetRole();
            extendedAddress       = new HardwareAddress(wpanApi.GetMac_15_4_Laddr().bytes);
            hardwareAddress       = new HardwareAddress(wpanApi.GetPropHwaddr().bytes);
            ipAddresses           = NetUtilities.SpinelIPtoSystemIP(wpanApi.GetIPv6AddressTable());

            ipLinkLocal = new IPAddress(wpanApi.GetIPv6LLAddr().bytes);
            ipMeshLocal = new IPAddress(wpanApi.GetIPv6MLAddr().bytes);
            lastStatus  = (SpinelStatus)wpanApi.GetPropLastStatus();
        }
Example #5
0
        private void ReadInitialValues()
        {
            LowpanIdentity   = new LowpanIdentity(wpanApi);
            LowpanCredential = new LowpanCredential(wpanApi);

            ncpVersion        = wpanApi.DoNCPVersion();
            protocolVersion   = wpanApi.DoProtocolVersion();
            interfaceType     = (InterfaceType)wpanApi.DoInterfaceType();
            vendor            = wpanApi.DoVendor();
            capabilities      = wpanApi.DoCaps();
            supportedChannels = wpanApi.DoChannels();
            scanMask          = wpanApi.DoChannelsMask();

            networkInterfaceState = wpanApi.DoInterfaceConfig();
            threadStackState      = wpanApi.DoThread();
            state           = (State)wpanApi.DoState();
            extendedAddress = new HardwareAddress(wpanApi.DoExtendedAddress().bytes);
            hardwareAddress = new HardwareAddress(wpanApi.DoPhysicalAddress().bytes);
            ipAddresses     = NetUtilities.SpinelIPtoSystemIP(wpanApi.DoIPAddresses());

            ipLinkLocal = new IPv6Address(wpanApi.DoIPLinkLocal64().bytes);
            ipMeshLocal = new IPv6Address(wpanApi.DoIPMeshLocal64().bytes);
        }
Example #6
0
 public DhcpClientIdentifier(HardwareAddress clientHardwareAddress)
 {
     ClientHardwareAddress = clientHardwareAddress;
 }