From 3c5f73e4d39aff17d8045a8bb950c4ab18f5b55d Mon Sep 17 00:00:00 2001 From: gpotter2 Date: Mon, 15 Jan 2018 19:57:03 +0100 Subject: [PATCH] Fix inet_pton PY3 --- scapy/compat.py | 4 ++-- scapy/pton_ntop.py | 4 +--- test/dnssecRR.uts | 5 +++++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/scapy/compat.py b/scapy/compat.py index 1737c046a..d00029a7b 100644 --- a/scapy/compat.py +++ b/scapy/compat.py @@ -77,7 +77,7 @@ if six.PY2: def plain_str(x): """Convert basic byte objects to str""" - return x + return x if isinstance(x, basestring) else str(x) def chb(x): """Same than chr() but encode as bytes. @@ -101,7 +101,7 @@ else: """Convert basic byte objects to str""" if isinstance(x, bytes): return x.decode('utf8') - return x + return x if isinstance(x, str) else str(x) def chb(x): """Same than chr() but encode as bytes. diff --git a/scapy/pton_ntop.py b/scapy/pton_ntop.py index 07793361d..b54a62c13 100644 --- a/scapy/pton_ntop.py +++ b/scapy/pton_ntop.py @@ -80,10 +80,8 @@ _INET_PTON = { def inet_pton(af, addr): """Convert an IP address from text representation into binary form.""" # Will replace Net/Net6 objects - if not isinstance(addr, str): - addr = str(addr) - # Use inet_pton if available addr = plain_str(addr) + # Use inet_pton if available try: return socket.inet_pton(af, addr) except AttributeError: diff --git a/test/dnssecRR.uts b/test/dnssecRR.uts index ab165bdbd..63599ad58 100644 --- a/test/dnssecRR.uts +++ b/test/dnssecRR.uts @@ -117,6 +117,11 @@ t.rrname == b'isc.org.' and t.keytag == 12892 and t.algorithm == 5 and t.digestt = DNSRR(type="TXT") instanciation t = DNSRR(type="TXT", rdata="test") += Build DNSRR +an = DNSRR(type='AAAA', rdata='2001::1') +an = DNSRR(raw(an)) +assert an.rdata == '2001::1' + = DNSRRR(), check parameters t = DNSRR(b'\x04test\x00\x00\x10\x00\x01\x00\x00\x00\x00\x018\xffScapy is an interactive packet manipulation program that enables you to sniff, mangle, send network packets ; test equipments ; probe and discover networks ; quickly develop new protocols. It can easily handle most classical tasks like scanning, tracerout7ing, probing, unit tests, attacks or network discovery.') t.type == 16 and t.rdlen == 312 and t.rdata[:5] == b"Scapy" and t.rdata[-10:] == b"discovery."