How nishayo/dns_resolver works
Main Components
• DNS Query Module: Represented by the source file (src/dns_query.c) – this component is responsible for constructing DNS query packets, handling UDP socket creation and communication on port 53, and sending the query.
• DNS Response Module: Represented by (src/dns_response.c) – this module handles the reception and parsing of DNS responses, including decoding A, AAAA, and CNAME records.
• Main Driver: The (src/main.c) file acts as the orchestrator that initializes the process, invokes the query and response modules, and handles command-line arguments (e.g., the domain name).
• Header Definitions: The (include/dns.h) file contains the necessary definitions, constants, and function declarations utilized by the other modules.
• Build & Configuration: The Makefile handles compiling and linking the source code, while setup instructions are provided in the README.
Relationships and Interactions
• The Main Driver calls functions in the DNS Query Module to construct and dispatch the queries.
• It then waits for a response from the external DNS server (Google DNS, port 53) and hands the received data to the DNS Response Module for processing.
• The DNS Response Module parses the packet, extracts the necessary records (A, AAAA, and possibly CNAME), and returns structured results back to the Main Driver.
• These interactions follow a sequential flow: User Input → Main Driver → DNS Query → External DNS Server → DNS Response → Output Display.
Architectural Patterns and Design Principles
• Modular Design: Each primary function (querying, response parsing) is clearly separated into modules (dns_query.c and dns_response.c) with their declarations in a common header (include/dns.h).
• Layered Abstraction: The main application logic (in src/main.c) abstracts away the lower-level details of packet handling from the user.
• External Communication: The design clearly delineates internal processing from external UDP communication with a designated DNS server.
Relevant Technologies, Frameworks, and Libraries
• Language: C with socket programming facilities provided by the Linux/Unix environment.
• Build System: The Make build system controlled via the Makefile.
• External Dependency: Google DNS server at 8.8.8.8 is an integral part of the operational flow.
• Main Driver (src/main.c):
• Input handling (command-line arguments)
• Orchestration of DNS query and response processing
• DNS Query Module (src/dns_query.c):
• Builds DNS query packet
• Handles UDP socket communication (send function)
• DNS Response Module (src/dns_response.c):
• Receives DNS response data
• Parses response, handling A, AAAA and CNAME records
• Header File (include/dns.h):
• Shared definitions and prototypes
• External component:
• Google DNS Server (8.8.8.8) with an annotation “UDP port 53”
• Build/Configuration:
• Makefile indicating the build process, and additional notes from README pertaining to environment and dependencies.