packet lib: udp: fix default arguments

Reported-by: Arne Goetje <arne_goetje@accton.com>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Minoru TAKAHASHI 2014-07-30 14:32:33 +09:00 committed by FUJITA Tomonori
parent 27c0cd5b11
commit be9db8b3f2
3 changed files with 10 additions and 10 deletions

View File

@ -41,7 +41,7 @@ class udp(packet_base.PacketBase):
_PACK_STR = '!HHHH'
_MIN_LEN = struct.calcsize(_PACK_STR)
def __init__(self, src_port=0, dst_port=0, total_length=0, csum=0):
def __init__(self, src_port=1, dst_port=1, total_length=0, csum=0):
super(udp, self).__init__()
self.src_port = src_port
self.dst_port = dst_port

View File

@ -911,16 +911,16 @@ class TestPacket(unittest.TestCase):
# udp
ok_(p_udp)
eq_(0, p_udp.src_port)
eq_(0, p_udp.dst_port)
eq_(1, p_udp.src_port)
eq_(1, p_udp.dst_port)
eq_(len(u_buf) + len(self.payload), p_udp.total_length)
eq_(0x2B62, p_udp.csum)
eq_(0x2B60, p_udp.csum)
t = bytearray(u_buf)
struct.pack_into('!H', t, 6, p_udp.csum)
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
len(u_buf) + len(self.payload), 17)
t = ph + t + self.payload
eq_(packet_utils.checksum(t), 0x60)
eq_(packet_utils.checksum(t), 0x62)
# payload
ok_('payload' in protocols)
@ -949,10 +949,10 @@ class TestPacket(unittest.TestCase):
if k in ipv6_values])
ipv6_str = '%s(%s)' % (ipv6.ipv6.__name__, _ipv6_str)
udp_values = {'src_port': 0,
'dst_port': 0,
udp_values = {'src_port': 1,
'dst_port': 1,
'total_length': len(u_buf) + len(self.payload),
'csum': 0x2B62}
'csum': 0x2B60}
_udp_str = ','.join(['%s=%s' % (k, repr(udp_values[k]))
for k, v in inspect.getmembers(p_udp)
if k in udp_values])

View File

@ -101,8 +101,8 @@ class Test_udp(unittest.TestCase):
buf = u.serialize(bytearray(), prev)
res = struct.unpack(udp._PACK_STR, buf)
eq_(res[0], 0)
eq_(res[1], 0)
eq_(res[0], 1)
eq_(res[1], 1)
eq_(res[2], udp._MIN_LEN)
def test_json(self):