delvingbitcoin

Hardcoded seeds, DNS seeds and Darknet nodes

Hardcoded seeds, DNS seeds and Darknet nodes

Posted on: September 11, 2024 07:43 UTC

The email discusses a technical solution for querying DNS records without the need for adding a dependency library, specifically addressing the limitations of getaddrinfo which only returns A and AAAA records.

The author shares their insights gained from writing a seeder, noting that DNS queries can be refreshingly straightforward. To illustrate this point, a C++ code snippet is provided to demonstrate how to send and receive a NULL query, a task deemed necessary due to getaddrinfo's limitations.

The C++ code outlined includes several key components crucial for constructing and executing a DNS query. Initially, it defines two structures: DNSHeader and DNSQuestion, which are essential for forming the DNS query. The DNSQuestion structure includes a method to convert a domain name into the DNS format, which involves prefixing each part of the domain with its length and terminating it with a null byte. This formatting is critical for DNS queries as it adheres to the protocol's requirements.

To demonstrate a practical example, the code sets up a DNS query for the domain "dnsseed.21.ninja" using a specified nameserver's IP address. It meticulously constructs the query by initializing a DNS header with specific flags indicating a desire for recursion and appending a DNS question formatted according to the DNS protocol. The question specifies a NULL record type, showcasing how to query types other than the standard A and AAAA records mentioned earlier.

The process involves creating a UDP socket, sending the formatted query to the specified nameserver, and then waiting for a response. Upon receiving a reply, the code outputs details about the sent query and the received reply, including sizes and header IDs, demonstrating the round-trip communication involved in DNS querying.

This example not only highlights the simplicity and directness of DNS queries when handled at a lower level but also serves as an educational tool for understanding the mechanics of DNS communication beyond the conventional use of higher-level libraries or functions that abstract these details away.