public void OnlyZeroesMinLen() { byte[] b = new byte[312]; Assert.Equal(312, b.Length); Assert.Throws <DHCPException>( () => DHCPPacketFactory.Read(b) ); }
public void TestTooLong() { byte[] b = new byte[577]; Assert.Equal(577, b.Length); Assert.Throws <DHCPException>( () => DHCPPacketFactory.Read(b) ); }
public void Only0xFFMinLen() { byte[] b = new byte[312]; for (int i = 0; i < b.Length; i++) { b[i] = 0xff; } Assert.Throws <DHCPException>( () => DHCPPacketFactory.Read(b) ); }
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); }
public void RawOffer() { byte[] b = RawData.Offer; byte[] pb = DHCPPacketFactory.Read(b).GetRawBytes(); Assert.Equal(b.Length, pb.Length); for (int i = 0; i < b.Length; i++) { byte expected = b[i]; byte actual = pb[i]; Assert.True( expected == actual, string.Format( "Expected: '0x{0:x2}', Actual: '0x{1:x2}' at offset {2}.", (byte)expected, (byte)actual, i)); } }
public void TestTooShort() { Assert.Throws <DHCPException>( () => DHCPPacketFactory.Read(new byte[] { 0 }) ); }
public void TestEmpty() { Assert.Throws <DHCPException>( () => DHCPPacketFactory.Read(new byte[] { }) ); }