| 252 | # comments are taken from rfc1035 |
| 253 | @dataclass |
| 254 | class DNSMessage(serializable.SerializableDataclass): |
| 255 | HEADER: ClassVar[struct.Struct] = struct.Struct("!HHHHHH") |
| 256 | |
| 257 | id: int |
| 258 | """An identifier assigned by the program that generates any kind of query.""" |
| 259 | query: bool |
| 260 | """A field that specifies whether this message is a query.""" |
| 261 | op_code: int |
| 262 | """ |
| 263 | A field that specifies kind of query in this message. |
| 264 | This value is set by the originator of a request and copied into the response. |
| 265 | """ |
| 266 | authoritative_answer: bool |
| 267 | """ |
| 268 | This field is valid in responses, and specifies that the responding name server |
| 269 | is an authority for the domain name in question section. |
| 270 | """ |
| 271 | truncation: bool |
| 272 | """Specifies that this message was truncated due to length greater than that permitted on the transmission channel.""" |
| 273 | recursion_desired: bool |
| 274 | """ |
| 275 | This field may be set in a query and is copied into the response. |
| 276 | If set, it directs the name server to pursue the query recursively. |
| 277 | """ |
| 278 | recursion_available: bool |
| 279 | """This field is set or cleared in a response, and denotes whether recursive query support is available in the name server.""" |
| 280 | reserved: int |
| 281 | """Reserved for future use. Must be zero in all queries and responses.""" |
| 282 | response_code: int |
| 283 | """This field is set as part of responses.""" |
| 284 | questions: list[Question] |
| 285 | """ |
| 286 | The question section is used to carry the "question" in most queries, i.e. |
| 287 | the parameters that define what is being asked. |
| 288 | """ |
| 289 | answers: list[ResourceRecord] |
| 290 | """First resource record section.""" |
| 291 | authorities: list[ResourceRecord] |
| 292 | """Second resource record section.""" |
| 293 | additionals: list[ResourceRecord] |
| 294 | """Third resource record section.""" |
| 295 | |
| 296 | timestamp: float | None = None |
| 297 | """The time at which the message was sent or received.""" |
| 298 | |
| 299 | def __str__(self) -> str: |
| 300 | return "\r\n".join( |
| 301 | map( |
| 302 | str, |
| 303 | itertools.chain( |
| 304 | self.questions, self.answers, self.authorities, self.additionals |
| 305 | ), |
| 306 | ) |
| 307 | ) |
| 308 | |
| 309 | @property |
| 310 | def content(self) -> bytes: |
| 311 | return self.packed |
no outgoing calls
no test coverage detected
searching dependent graphs…