Skip to content

Commit 8dbc779

Browse files
authored
Merge pull request #1168 from guedou/niq_fixes
NIQ fixes
2 parents a0ddbc3 + 29b5f64 commit 8dbc779

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
@@ -2222,7 +2222,7 @@ class ICMPv6ND_INDAdv(_ICMPv6NDGuessPayload, _ICMPv6):
22222222

22232223
class _ICMPv6NIHashret:
22242224
def hashret(self):
2225-
return self.nonce
2225+
return raw(self.nonce)
22262226

22272227
class _ICMPv6NIAnswers:
22282228
def answers(self, other):
@@ -2357,7 +2357,6 @@ def h2i(self, pkt, x):
23572357
return (1, x)
23582358

23592359
def i2repr(self, pkt, x):
2360-
x = plain_str(x)
23612360
t,val = x
23622361
if t == 1: # DNS Name
23632362
# we don't use dnsrepr2names() to deal with
@@ -2368,7 +2367,7 @@ def i2repr(self, pkt, x):
23682367
val = val[1:]
23692368
if l == 0:
23702369
break
2371-
res.append(val[:l]+".")
2370+
res.append(plain_str(val[:l])+".")
23722371
val = val[l:]
23732372
tmp = "".join(res)
23742373
if tmp and tmp[-1] == '.':
@@ -2590,7 +2589,8 @@ def i2repr(self, pkt, x):
25902589
if t == 2: # DNS names
25912590
ttl,l = val
25922591
l = dnsrepr2names(l)
2593-
return "ttl:%d %s" % (ttl, ", ".join(l))
2592+
names_list = (plain_str(name) for name in l)
2593+
return "ttl:%d %s" % (ttl, ",".join(names_list))
25942594
elif t == 3 or t == 4:
25952595
return "[ %s ]" % (", ".join(map(lambda x_y: "(%d, %s)" % (x_y[0], x_y[1]), val)))
25962596
return repr(val)

test/regression.uts

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

2984+
= ICMPv6NIQueryName - dissection
2985+
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'
2986+
p = ICMPv6NIQueryName(s)
2987+
p.show()
2988+
assert ICMPv6NIQueryName in p and p.data == "ff02::1"
2989+
29842990

29852991
############
29862992
############
@@ -3049,6 +3055,20 @@ type(a) is tuple and len(a) == 2 and a[0] == 2 and a[1] == '169.254.253.252'
30493055
= ICMPv6NIQueryIPv4 - IPv4 address
30503056
ICMPv6NIQueryIPv4(data="169.254.253.252").data == '169.254.253.252'
30513057

3058+
= ICMPv6NIQueryIPv4 - dissection
3059+
s = b'\x8b\x01\x00\x00\x00\x04\x00\x00\xc2\xb9\xc2\x96\xc3\xa1.H\x07freebsd\x00\x00'
3060+
p = ICMPv6NIQueryIPv4(s)
3061+
p.show()
3062+
assert ICMPv6NIQueryIPv4 in p and p.data == b"freebsd"
3063+
3064+
= ICMPv6NIQueryIPv4 - hashret()
3065+
~ not_pypy random_weird_py3
3066+
random.seed(0x2807)
3067+
p = IPv6()/ICMPv6NIQueryIPv4(data="freebsd")
3068+
h_py2 = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:\xe10S7\x9d\x91\x84\xc9'
3069+
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'
3070+
assert p.hashret() in [h_py2, h_py3]
3071+
30523072

30533073
############
30543074
############
@@ -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[
32783298
= ICMPv6NIReplyName - [ttl, single-label, single-label, fqdn]
32793299
ICMPv6NIReplyName(data=[42, "abricot", "poire", "n.d.tld"]).data == [42, b"abricot", b"poire", b"n.d.tld"]
32803300

3301+
= ICMPv6NIReplyName - dissection
3302+
3303+
s = b'\x8c\x00\xd1\x0f\x00\x02\x00\x00\x00\x00\xd9$\x94\x8d\xc6%\x00\x00\x00\x00\x07freebsd\x00\x00'
3304+
p = ICMPv6NIReplyName(s)
3305+
p.show()
3306+
assert ICMPv6NIReplyName in p and p.data == [0, b'freebsd']
3307+
32813308

32823309
############
32833310
############

0 commit comments

Comments
 (0)