MCPcopy Create free account
hub / github.com/secdev/scapy / dns_encode

Function dns_encode

scapy/layers/dns.py:211–229  ·  view source on GitHub ↗

Encodes a bytes string into the DNS format :param x: the string :param check_built: detect already-built strings and ignore them :returns: the encoded bytes string

(x, check_built=False)

Source from the content-addressed store, hash-verified

209
210
211def dns_encode(x, check_built=False):
212 """Encodes a bytes string into the DNS format
213
214 :param x: the string
215 :param check_built: detect already-built strings and ignore them
216 :returns: the encoded bytes string
217 """
218 if not x or x == b".":
219 return b"\x00"
220
221 if check_built and _is_ptr(x):
222 # The value has already been processed. Do not process it again
223 return x
224
225 # Truncate chunks that cannot be encoded (more than 63 bytes..)
226 x = b"".join(chb(len(y)) + y for y in (k[:63] for k in x.split(b".")))
227 if x[-1:] != b"\x00":
228 x += b"\x00"
229 return x
230
231
232def DNSgetstr(*args, **kwargs):

Callers 2

dns_compressFunction · 0.85
i2mMethod · 0.85

Calls 3

chbFunction · 0.90
_is_ptrFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…