packet lib: calculate the ip total length

If the total length is not given, calculate it.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
FUJITA Tomonori 2012-08-27 11:37:25 +09:00
parent d0cc259e3b
commit 79ae375136

View File

@ -72,6 +72,8 @@ class ipv4(packet_base.PacketBase):
hdr = bytearray().zfill(self.header_length * 4)
version = self.version << 4 | self.header_length
flags = self.flags << 15 | self.offset
if self.total_length == 0:
self.total_length = self.header_length * 4 + len(payload)
struct.pack_into(ipv4._PACK_STR, hdr, 0, version, self.tos,
self.total_length, self.identification, flags,
self.ttl, self.proto, 0, self.src, self.dst)