packet lib: icmp support time exceeded type

Used mainly for traceroute.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
FUJITA Tomonori 2013-06-10 11:32:19 +09:00
parent e89eb36465
commit d33ef49213

View File

@ -24,6 +24,7 @@ ICMP_DEST_UNREACH = 3
ICMP_SRC_QUENCH = 4
ICMP_REDIRECT = 5
ICMP_ECHO_REQUEST = 8
ICMP_TIME_EXCEEDED = 11
class icmp(packet_base.PacketBase):
@ -146,3 +147,20 @@ class echo(object):
hdr += self.data
return hdr
@icmp.register_icmp_type(ICMP_TIME_EXCEEDED)
class TimeExceeded(object):
_PACK_STR = '!4x'
_MIN_LEN = struct.calcsize(_PACK_STR)
def __init__(self, data=None):
self.data = data
def serialize(self):
hdr = bytearray(TimeExceeded._MIN_LEN)
if self.data is not None:
hdr += self.data
return hdr