"""
if isinstance(what, dns.message.Message):
- wire = what.to_wire()
+ tcpmsg = what.to_wire(prepend_length=True)
else:
- wire = what
- l = len(wire)
- # copying the wire into tcpmsg is inefficient, but lets us
- # avoid writev() or doing a short write that would get pushed
- # onto the net
- tcpmsg = struct.pack("!H", l) + wire
+ # copying the wire into tcpmsg is inefficient, but lets us
+ # avoid writev() or doing a short write that would get pushed
+ # onto the net
+ tcpmsg = len(what).to_bytes(2, 'big') + what
sent_time = time.time()
await sock.sendall(tcpmsg, _timeout(expiration, sent_time))
return (len(tcpmsg), sent_time)
max_size: int = 0,
multi: bool = False,
tsig_ctx: Optional[Any] = None,
+ prepend_length : bool = False,
**kw: Dict[str, Any],
) -> bytes:
"""Return a string containing the message in DNS compressed wire
*tsig_ctx*, a ``dns.tsig.HMACTSig`` or ``dns.tsig.GSSTSig`` object, the
ongoing TSIG context, used when signing zone transfers.
+ *prepend_length", a ``bool``, should be set to ``True`` if the caller
+ wants the message length prepended to the message itself. This is
+ useful for messages sent over TCP, TLS (DoT), or QUIC (DoQ).
+
Raises ``dns.exception.TooBig`` if *max_size* was exceeded.
Returns a ``bytes``.
r.write_header()
if multi:
self.tsig_ctx = ctx
- return r.get_wire()
+ wire = r.get_wire()
+ if prepend_length:
+ wire = len(wire).to_bytes(2, 'big') + wire
+ return wire
@staticmethod
def _make_tsig(
"""
if isinstance(what, dns.message.Message):
- wire = what.to_wire()
+ tcpmsg = what.to_wire(prepend_length=True)
else:
- wire = what
- l = len(wire)
- # copying the wire into tcpmsg is inefficient, but lets us
- # avoid writev() or doing a short write that would get pushed
- # onto the net
- tcpmsg = struct.pack("!H", l) + wire
+ # copying the wire into tcpmsg is inefficient, but lets us
+ # avoid writev() or doing a short write that would get pushed
+ # onto the net
+ tcpmsg = len(what).to_bytes(2, 'big') + what
sent_time = time.time()
_net_write(sock, tcpmsg, expiration)
return (len(tcpmsg), sent_time)