diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-08-27 11:37:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-08-28 05:58:25 +0900 |
commit | 4e887d03c80e6bbd39a1898a0bd929d16f26aa09 (patch) | |
tree | 46ad27c7dd22e5eb11164c881ec9102c648c2613 | |
parent | 79ae3751360554cb2324fb22341631049aa900a4 (diff) |
packet lib: calculate the udp length
If the length is not given, calculate it.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/udp.py | 5 |
1 files 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) |