From 161ffd8cb8de09582f77964b5f0a1b47c0fff963 Mon Sep 17 00:00:00 2001 From: Phil <phil@secdev.org> Date: Fri, 6 Aug 2010 16:59:54 +0200 Subject: [PATCH] Fixed DNS name encoding for '.' with (fixed) patch from ticket #354 --- scapy/layers/dns.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scapy/layers/dns.py b/scapy/layers/dns.py index 7ca570e1..e8f941a8 100644 --- a/scapy/layers/dns.py +++ b/scapy/layers/dns.py @@ -11,15 +11,29 @@ from scapy.ansmachine import * from scapy.layers.inet import UDP class DNSStrField(StrField): + + def h2i(self, pkt, x): + if x == "": + return "." + return x + def i2m(self, pkt, x): - x = [k[:63] for k in x.split(".")] # Truncate chunks that cannont be encoded (more than 63 bytes..) + if x == ".": + return "\x00" + + x = [k[:63] for k in x.split(".")] # Truncate chunks that cannot be encoded (more than 63 bytes..) x = map(lambda y: chr(len(y))+y, x) x = "".join(x) if x[-1] != "\x00": x += "\x00" return x + def getfield(self, pkt, s): n = "" + + if ord(s[0]) == 0: + return s[1:], "." + while 1: l = ord(s[0]) s = s[1:] -- GitLab