Exemplo n.º 1
0
    def test_tcp_with_options(self):
        """Assert that a TCP with options is correctly encoded."""
        packet = tcp()

        nop = pcs.Field("nop", 8)
        mss = pcs.TypeLengthValueField("mss", pcs.Field("t", 8, default=0x02),
                                       pcs.Field("l", 8), pcs.Field("v", 16))
        end = pcs.Field("end", 8)

        nop.value = 1
        mss.value.value = 1460  # Most common Internet MSS value.

        # Build a TCP option list which will be 32-bits aligned.
        packet.options.append(nop)
        packet.options.append(nop)
        packet.options.append(mss)
        packet.options.append(nop)
        packet.options.append(end)

        expected = "\x00\x00\x00\x00\x00\x00\x00\x00" \
            "\x00\x00\x00\x00\x00\x00\x00\x00" \
            "\x00\x00\x00\x00\x01\x01\x02\x04" \
            "\x05\xb4\x01\x00"
        got = packet.bytes

        #packet.encode()
        #hd = hexdumper()
        #print hd.dump(expected)
        #print hd.dump(got)

        # XXX: Note well: just because you added an option list,
        # doesn't mean the TCP option length is correct.

        self.assertEqual(expected, got)
Exemplo n.º 2
0
    def test_tcp_without_options(self):
	"""Assert that a TCP without options does not get any additional
	   fields appended to it on the wire."""
        packet = tcp()

	expected = "\x00\x00\x00\x00\x00\x00\x00\x00" \
		   "\x00\x00\x00\x00\x50\x00\x00\x00" \
		   "\x00\x00\x00\x00"
	got = packet.bytes

	#packet.encode()
	#hd = hexdumper()
	#print hd.dump(expected)
	#print hd.dump(got)

	self.assertEqual(len(packet.options), 0)
        self.assertEqual(expected, got)
Exemplo n.º 3
0
    def test_tcp_without_options(self):
        """Assert that a TCP without options does not get any additional
	   fields appended to it on the wire."""
        packet = tcp()

        expected = "\x00\x00\x00\x00\x00\x00\x00\x00" \
            "\x00\x00\x00\x00\x00\x00\x00\x00" \
            "\x00\x00\x00\x00"
        got = packet.bytes

        #packet.encode()
        #hd = hexdumper()
        #print hd.dump(expected)
        #print hd.dump(got)

        self.assertEqual(len(packet.options), 0)
        self.assertEqual(expected, got)
Exemplo n.º 4
0
    def test_tcp_with_options(self):
	"""Assert that a TCP with options is correctly encoded."""
        packet = tcp()

        nop = pcs.Field("nop", 8)
	mss = pcs.TypeLengthValueField("mss",
	                               pcs.Field("t", 8, default = 0x02),
				       pcs.Field("l", 8),
				       pcs.Field("v", 16))
        end = pcs.Field("end", 8)

        nop.value = 1
        mss.value.value = 1460		# Most common Internet MSS value.

	# Build a TCP option list which will be 32-bits aligned.
        packet.options.append(nop)
        packet.options.append(nop)
        packet.options.append(mss)
        packet.options.append(nop)
        packet.options.append(end)

	expected = "\x00\x00\x00\x00\x00\x00\x00\x00" \
		   "\x00\x00\x00\x00\x50\x00\x00\x00" \
		   "\x00\x00\x00\x00\x01\x01\x02\x04" \
		   "\x05\xb4\x01\x00"
	got = packet.bytes

	#packet.encode()
	#hd = hexdumper()
	#print hd.dump(expected)
	#print hd.dump(got)

	# XXX: Note well: just because you added an option list,
	# doesn't mean the TCP option length is correct.

        self.assertEqual(expected, got)