packet lib: icmp: support len(icmp.*)

Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Yuichi Ito 2013-11-06 17:16:23 +09:00 committed by FUJITA Tomonori
parent 1d1cdeea99
commit 8de99416fa

View File

@ -115,6 +115,9 @@ class icmp(packet_base.PacketBase):
return hdr
def __len__(self):
return self._MIN_LEN + len(self.data)
@icmp.register_icmp_type(ICMP_ECHO_REPLY, ICMP_ECHO_REQUEST)
class echo(stringify.StringifyMixin):
@ -167,6 +170,12 @@ class echo(stringify.StringifyMixin):
return hdr
def __len__(self):
length = self._MIN_LEN
if self.data is not None:
length += len(self.data)
return length
@icmp.register_icmp_type(ICMP_DEST_UNREACH)
class dest_unreach(stringify.StringifyMixin):
@ -227,6 +236,12 @@ class dest_unreach(stringify.StringifyMixin):
return hdr
def __len__(self):
length = self._MIN_LEN
if self.data is not None:
length += len(self.data)
return length
@icmp.register_icmp_type(ICMP_TIME_EXCEEDED)
class TimeExceeded(stringify.StringifyMixin):
@ -276,3 +291,9 @@ class TimeExceeded(stringify.StringifyMixin):
hdr += self.data
return hdr
def __len__(self):
length = self._MIN_LEN
if self.data is not None:
length += len(self.data)
return length