Merge pull request #1168 from guedou/niq_fixes

NIQ fixes
This commit is contained in:
Pierre Lalet 2018-03-24 19:24:02 +01:00 committed by GitHub
commit 8dbc7796b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -2222,7 +2222,7 @@ icmp6_niqtypes = { 0: "NOOP",
class _ICMPv6NIHashret:
def hashret(self):
return self.nonce
return raw(self.nonce)
class _ICMPv6NIAnswers:
def answers(self, other):
@ -2357,7 +2357,6 @@ class NIQueryDataField(StrField):
return (1, x)
def i2repr(self, pkt, x):
x = plain_str(x)
t,val = x
if t == 1: # DNS Name
# we don't use dnsrepr2names() to deal with
@ -2368,7 +2367,7 @@ class NIQueryDataField(StrField):
val = val[1:]
if l == 0:
break
res.append(val[:l]+".")
res.append(plain_str(val[:l])+".")
val = val[l:]
tmp = "".join(res)
if tmp and tmp[-1] == '.':
@ -2590,7 +2589,8 @@ class NIReplyDataField(StrField):
if t == 2: # DNS names
ttl,l = val
l = dnsrepr2names(l)
return "ttl:%d %s" % (ttl, ", ".join(l))
names_list = (plain_str(name) for name in l)
return "ttl:%d %s" % (ttl, ",".join(names_list))
elif t == 3 or t == 4:
return "[ %s ]" % (", ".join(map(lambda x_y: "(%d, %s)" % (x_y[0], x_y[1]), val)))
return repr(val)

View File

@ -2981,6 +2981,12 @@ s = raw(IPv6()/ICMPv6NIQueryName(data="n.d.org"))
p = IPv6(s)
ICMPv6NIQueryName in p and p[ICMPv6NIQueryName].data == b"n.d.org"
= ICMPv6NIQueryName - dissection
s = b'\x8b\x00z^\x00\x02\x00\x00\x00\x03g\x90\xc7\xa3\xdd[\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
p = ICMPv6NIQueryName(s)
p.show()
assert ICMPv6NIQueryName in p and p.data == "ff02::1"
############
############
@ -3049,6 +3055,20 @@ type(a) is tuple and len(a) == 2 and a[0] == 2 and a[1] == '169.254.253.252'
= ICMPv6NIQueryIPv4 - IPv4 address
ICMPv6NIQueryIPv4(data="169.254.253.252").data == '169.254.253.252'
= ICMPv6NIQueryIPv4 - dissection
s = b'\x8b\x01\x00\x00\x00\x04\x00\x00\xc2\xb9\xc2\x96\xc3\xa1.H\x07freebsd\x00\x00'
p = ICMPv6NIQueryIPv4(s)
p.show()
assert ICMPv6NIQueryIPv4 in p and p.data == b"freebsd"
= ICMPv6NIQueryIPv4 - hashret()
~ not_pypy random_weird_py3
random.seed(0x2807)
p = IPv6()/ICMPv6NIQueryIPv4(data="freebsd")
h_py2 = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:\xe10S7\x9d\x91\x84\xc9'
h_py3 = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:\xa8\x19uE\x01\xcf\xe3\x04'
assert p.hashret() in [h_py2, h_py3]
############
############
@ -3278,6 +3298,13 @@ type(a) is tuple and len(a) == 2 and a[0] == 2 and type(a[1]) is list and len(a[
= ICMPv6NIReplyName - [ttl, single-label, single-label, fqdn]
ICMPv6NIReplyName(data=[42, "abricot", "poire", "n.d.tld"]).data == [42, b"abricot", b"poire", b"n.d.tld"]
= ICMPv6NIReplyName - dissection
s = b'\x8c\x00\xd1\x0f\x00\x02\x00\x00\x00\x00\xd9$\x94\x8d\xc6%\x00\x00\x00\x00\x07freebsd\x00\x00'
p = ICMPv6NIReplyName(s)
p.show()
assert ICMPv6NIReplyName in p and p.data == [0, b'freebsd']
############
############