From 4e887d03c80e6bbd39a1898a0bd929d16f26aa09 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Mon, 27 Aug 2012 11:37:26 +0900 Subject: packet lib: calculate the udp length If the length is not given, calculate it. Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/udp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ryu/lib/packet/udp.py b/ryu/lib/packet/udp.py index 11f3ad22..05973c70 100644 --- a/ryu/lib/packet/udp.py +++ b/ryu/lib/packet/udp.py @@ -20,13 +20,12 @@ from . import packet_base class udp(packet_base.PacketBase): _PACK_STR = '!HHHH' - def __init__(self, src_port, dst_port, length, csum=0, data=None): + def __init__(self, src_port, dst_port, length, csum=0): super(udp, self).__init__() self.src_port = src_port self.dst_port = dst_port self.length = length self.csum = csum - self.data = data @classmethod def parser(cls, buf): @@ -39,5 +38,7 @@ class udp(packet_base.PacketBase): return msg, None def serialize(self, payload, prev): + if self.length == 0: + self.length = struct.calcsize(udp._PACK_STR) + len(payload) return struct.pack(udp._PACK_STR, self.src_port, self.dst_port, self.length, self.csum) -- cgit v1.2.3