packet lib: udp: support default parameters
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:
parent
96d5be05e0
commit
ae9470136e
@ -41,7 +41,7 @@ class udp(packet_base.PacketBase):
|
||||
_PACK_STR = '!HHHH'
|
||||
_MIN_LEN = struct.calcsize(_PACK_STR)
|
||||
|
||||
def __init__(self, src_port, dst_port, total_length=0, csum=0):
|
||||
def __init__(self, src_port=0, dst_port=0, total_length=0, csum=0):
|
||||
super(udp, self).__init__()
|
||||
self.src_port = src_port
|
||||
self.dst_port = dst_port
|
||||
|
@ -94,3 +94,13 @@ class Test_udp(unittest.TestCase):
|
||||
def test_malformed_udp(self):
|
||||
m_short_buf = self.buf[1:udp._MIN_LEN]
|
||||
udp.parser(m_short_buf)
|
||||
|
||||
def test_default_args(self):
|
||||
prev = ipv4(proto=inet.IPPROTO_UDP)
|
||||
u = udp()
|
||||
buf = u.serialize(bytearray(), prev)
|
||||
res = struct.unpack(udp._PACK_STR, buf)
|
||||
|
||||
eq_(res[0], 0)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[2], udp._MIN_LEN)
|
||||
|
Loading…
Reference in New Issue
Block a user