Skip to content

Commit 29b5f64

Browse files
committed
Node Information Query Python3 fixed
1 parent 89a0771 commit 29b5f64

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

scapy/layers/inet6.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ class ICMPv6ND_INDAdv(_ICMPv6NDGuessPayload, _ICMPv6):
22202220

22212221
class _ICMPv6NIHashret:
22222222
def hashret(self):
2223-
return self.nonce
2223+
return raw(self.nonce)
22242224

22252225
class _ICMPv6NIAnswers:
22262226
def answers(self, other):
@@ -2355,7 +2355,6 @@ def h2i(self, pkt, x):
23552355
return (1, x)
23562356

23572357
def i2repr(self, pkt, x):
2358-
x = plain_str(x)
23592358
t,val = x
23602359
if t == 1: # DNS Name
23612360
# we don't use dnsrepr2names() to deal with
@@ -2366,7 +2365,7 @@ def i2repr(self, pkt, x):
23662365
val = val[1:]
23672366
if l == 0:
23682367
break
2369-
res.append(val[:l]+".")
2368+
res.append(plain_str(val[:l])+".")
23702369
val = val[l:]
23712370
tmp = "".join(res)
23722371
if tmp and tmp[-1] == '.':
@@ -2588,7 +2587,8 @@ def i2repr(self, pkt, x):
25882587
if t == 2: # DNS names
25892588
ttl,l = val
25902589
l = dnsrepr2names(l)
2591-
return "ttl:%d %s" % (ttl, ", ".join(l))
2590+
names_list = (plain_str(name) for name in l)
2591+
return "ttl:%d %s" % (ttl, ",".join(names_list))
25922592
elif t == 3 or t == 4:
25932593
return "[ %s ]" % (", ".join(map(lambda x_y: "(%d, %s)" % (x_y[0], x_y[1]), val)))
25942594
return repr(val)

test/regression.uts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,12 @@ s = raw(IPv6()/ICMPv6NIQueryName(data="n.d.org"))
29532953
p = IPv6(s)
29542954
ICMPv6NIQueryName in p and p[ICMPv6NIQueryName].data == b"n.d.org"
29552955

2956+
= ICMPv6NIQueryName - dissection
2957+
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'
2958+
p = ICMPv6NIQueryName(s)
2959+
p.show()
2960+
assert ICMPv6NIQueryName in p and p.data == "ff02::1"
2961+
29562962

29572963
############
29582964
############
@@ -3021,6 +3027,20 @@ type(a) is tuple and len(a) == 2 and a[0] == 2 and a[1] == '169.254.253.252'
30213027
= ICMPv6NIQueryIPv4 - IPv4 address
30223028
ICMPv6NIQueryIPv4(data="169.254.253.252").data == '169.254.253.252'
30233029

3030+
= ICMPv6NIQueryIPv4 - dissection
3031+
s = b'\x8b\x01\x00\x00\x00\x04\x00\x00\xc2\xb9\xc2\x96\xc3\xa1.H\x07freebsd\x00\x00'
3032+
p = ICMPv6NIQueryIPv4(s)
3033+
p.show()
3034+
assert ICMPv6NIQueryIPv4 in p and p.data == b"freebsd"
3035+
3036+
= ICMPv6NIQueryIPv4 - hashret()
3037+
~ not_pypy random_weird_py3
3038+
random.seed(0x2807)
3039+
p = IPv6()/ICMPv6NIQueryIPv4(data="freebsd")
3040+
h_py2 = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:\xe10S7\x9d\x91\x84\xc9'
3041+
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'
3042+
assert p.hashret() in [h_py2, h_py3]
3043+
30243044

30253045
############
30263046
############
@@ -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[
32503270
= ICMPv6NIReplyName - [ttl, single-label, single-label, fqdn]
32513271
ICMPv6NIReplyName(data=[42, "abricot", "poire", "n.d.tld"]).data == [42, b"abricot", b"poire", b"n.d.tld"]
32523272

3273+
= ICMPv6NIReplyName - dissection
3274+
3275+
s = b'\x8c\x00\xd1\x0f\x00\x02\x00\x00\x00\x00\xd9$\x94\x8d\xc6%\x00\x00\x00\x00\x07freebsd\x00\x00'
3276+
p = ICMPv6NIReplyName(s)
3277+
p.show()
3278+
assert ICMPv6NIReplyName in p and p.data == [0, b'freebsd']
3279+
32533280

32543281
############
32553282
############

0 commit comments

Comments
 (0)