Read a DNS message from a TCP socket. *sock*, a ``socket``. *expiration*, a ``float`` or ``None``, the absolute time at which a timeout exception should be raised. If ``None``, no timeout will occur. *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own R
(
sock: Any,
expiration: float | None = None,
one_rr_per_rrset: bool = False,
keyring: Dict[dns.name.Name, dns.tsig.Key] | None = None,
request_mac: bytes | None = b"",
ignore_trailing: bool = False,
)
| 1144 | |
| 1145 | |
| 1146 | def receive_tcp( |
| 1147 | sock: Any, |
| 1148 | expiration: float | None = None, |
| 1149 | one_rr_per_rrset: bool = False, |
| 1150 | keyring: Dict[dns.name.Name, dns.tsig.Key] | None = None, |
| 1151 | request_mac: bytes | None = b"", |
| 1152 | ignore_trailing: bool = False, |
| 1153 | ) -> Tuple[dns.message.Message, float]: |
| 1154 | """Read a DNS message from a TCP socket. |
| 1155 | |
| 1156 | *sock*, a ``socket``. |
| 1157 | |
| 1158 | *expiration*, a ``float`` or ``None``, the absolute time at which |
| 1159 | a timeout exception should be raised. If ``None``, no timeout will |
| 1160 | occur. |
| 1161 | |
| 1162 | *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own |
| 1163 | RRset. |
| 1164 | |
| 1165 | *keyring*, a ``dict``, the keyring to use for TSIG. |
| 1166 | |
| 1167 | *request_mac*, a ``bytes`` or ``None``, the MAC of the request (for TSIG). |
| 1168 | |
| 1169 | *ignore_trailing*, a ``bool``. If ``True``, ignore trailing |
| 1170 | junk at end of the received message. |
| 1171 | |
| 1172 | Raises if the message is malformed, if network errors occur, of if |
| 1173 | there is a timeout. |
| 1174 | |
| 1175 | Returns a ``(dns.message.Message, float)`` tuple of the received message |
| 1176 | and the received time. |
| 1177 | """ |
| 1178 | |
| 1179 | ldata = _net_read(sock, 2, expiration) |
| 1180 | (l,) = struct.unpack("!H", ldata) |
| 1181 | wire = _net_read(sock, l, expiration) |
| 1182 | received_time = time.time() |
| 1183 | r = dns.message.from_wire( |
| 1184 | wire, |
| 1185 | keyring=keyring, |
| 1186 | request_mac=request_mac, |
| 1187 | one_rr_per_rrset=one_rr_per_rrset, |
| 1188 | ignore_trailing=ignore_trailing, |
| 1189 | ) |
| 1190 | return (r, received_time) |
| 1191 | |
| 1192 | |
| 1193 | def _connect(s, address, expiration): |