aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Lalet <pierre@droids-corp.org>2018-01-20 00:28:25 +0100
committerGitHub <noreply@github.com>2018-01-20 00:28:25 +0100
commit2e4b3bcc7a36af5f7183288693cf449ce4f4726e (patch)
tree86d9f0c178e9c220aae0e69582b94f7d44a4a341
parenteab6e0eaf5bbc097befb22a994277114556fa24b (diff)
parent3c5f73e4d39aff17d8045a8bb950c4ab18f5b55d (diff)
downloadplatform_external_scapy-2e4b3bcc7a36af5f7183288693cf449ce4f4726e.tar.gz
platform_external_scapy-2e4b3bcc7a36af5f7183288693cf449ce4f4726e.tar.bz2
platform_external_scapy-2e4b3bcc7a36af5f7183288693cf449ce4f4726e.zip
Merge pull request #1055 from gpotter2/fix-pton
Fix inet_pton PY3
-rw-r--r--scapy/compat.py4
-rw-r--r--scapy/pton_ntop.py4
-rw-r--r--test/dnssecRR.uts5
3 files changed, 8 insertions, 5 deletions
diff --git a/scapy/compat.py b/scapy/compat.py
index 1737c046..d00029a7 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 07793361..b54a62c1 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 ab165bdb..63599ad5 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."