From 29b5f64e27bb6f12d50a43f93ed20eaf0bf6a661 Mon Sep 17 00:00:00 2001 From: Guillaume Valadon Date: Wed, 21 Feb 2018 14:21:31 +0100 Subject: [PATCH] Node Information Query Python3 fixed --- scapy/layers/inet6.py | 8 ++++---- test/regression.uts | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py index 767ba4796..f76d5df99 100644 --- a/scapy/layers/inet6.py +++ b/scapy/layers/inet6.py @@ -2220,7 +2220,7 @@ icmp6_niqtypes = { 0: "NOOP", class _ICMPv6NIHashret: def hashret(self): - return self.nonce + return raw(self.nonce) class _ICMPv6NIAnswers: def answers(self, other): @@ -2355,7 +2355,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 @@ -2366,7 +2365,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] == '.': @@ -2588,7 +2587,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) diff --git a/test/regression.uts b/test/regression.uts index a2a647f9a..78bb26a9c 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -2953,6 +2953,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" + ############ ############ @@ -3021,6 +3027,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] + ############ ############ @@ -3250,6 +3270,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'] + ############ ############