📝 DNS hierarchical name space (25 MCQs)
Root, Top-Level and Lower-Level Domain Structure
DNS names are arranged in a tree rooted at the DNS root, represented by a final dot. Beneath the root are top-level domains such as com, org and country-code domains. Lower-level labels identify registered domains and subdomains, allowing the namespace to scale through delegation rather than one central list of every host. Its distributed structure avoids reliance on one central database for every Internet name worldwide.
Labels, Fully Qualified Names and Delegation
A domain name consists of labels separated by dots, with the hierarchy read from right to left. A fully qualified domain name identifies a node down to the root, even when the final dot is omitted in common display. Administrative zones are portions of the tree served by authoritative name servers and can delegate child domains.
Following the DNS Hierarchy to a Zone
To resolve a name, a resolver begins with a query and follows referrals through the hierarchy. Root servers direct it toward the appropriate top-level domain, which can refer it to the domain's authoritative servers. Those servers supply records for names within their zones or further referrals for delegated subdomains. The lookup process combines local caching with referrals across delegated administrative zones.
Resolving a Host Under a Country Domain
For www.department.example.edu.pk, the labels are evaluated from the root toward pk, edu, example, department and www. The .pk registry hierarchy and delegated servers guide the lookup to authoritative data for the relevant zone. The final host label is not itself a separate top-level domain. The example links a human-readable name to data needed by an application.
Zones, Delegation and Authoritative Data
A DNS zone is an administratively managed part of the namespace and need not equal an entire domain tree. A parent zone can delegate a child domain using NS records, while the child zone maintains its own records. This division distributes responsibility and allows independent administration of organizational subdomains. This division supports scalable administration while keeping naming separate from packet forwarding.
Misreading Domain Levels and DNS Zones
'The leftmost label is the top-level domain' reverses the hierarchy; the rightmost label is nearest the root. 'A domain and a zone are always identical' ignores delegation boundaries. 'Every subdomain must use the same name servers as its parent' is false because a child can be delegated to separate authoritative servers.
Interpreting Domain Names from Right to Left
Parse names from right to left, identify the root and TLD, then locate registered and subdomain labels. Distinguish a fully qualified name from a relative name and a zone from a domain. In hierarchy diagrams, follow NS delegations to identify which authoritative servers hold the data for a requested name.
DNS Hierarchy and Delegation Terms
- Root - Top node of the DNS tree.
- TLD - Domain level directly below root.
- Label - Name component between DNS dots.
- FQDN - Fully identifies a name in DNS.
- Zone - Administratively managed DNS subtree.
- Delegation - Assigns child-zone authority elsewhere.
📝 All DNS hierarchical name space MCQs
Q1. Which function is used to bind a socket to an address?
📖 Explanation: The bind function associates a socket descriptor with a specific local address and port, which is necessary before the server can receive datagrams. It does not establish a connection (connect), listen for connections (listen), or accept incoming connections (accept). Hence option A is correct.
Q2. What is the primary purpose of the perror function in the echo server code?
📖 Explanation: perror examines the global errno variable and prints a human‑readable description of the last error, prefixed by a custom string. It aids debugging but does not affect program flow, memory allocation, or network transmission, making option A the accurate description.
Q3. If the recvfrom call blocks indefinitely, which of the following is the most likely cause?
📖 Explanation: recvfrom is a blocking call that waits for incoming data. If it never returns, the usual reason is that no datagram arrived from any client. Non‑blocking mode would cause an immediate error, and bind or buffer size issues would be detected earlier, so option A is correct.
Q4. Given the code fragment \text{len}= \text{recvfrom}(s, buffer, sizeof(buffer), 0, (struct sockaddr*)&clntAddr, &clntAddrLen);, what logical inference can be made about the value of len after a successful call?
📖 Explanation: recvfrom returns the number of bytes placed into the buffer, which is stored in len. It never returns zero on success unless an empty datagram is received, and it does not return address information, so the correct inference is that len equals the byte count.
Q5. Why might the server choose to call sendto with sizeof(clntAddr) instead of clntAddrLen when responding to the client?
📖 Explanation: Using sizeof(clntAddr) guarantees that the full sockaddr structure is supplied, regardless of the actual length stored in clntAddrLen. This prevents truncation errors that could arise if clntAddrLen were smaller than the structure size, making option A the most logical justification.
Q6. In the infinite loop of the server, which logical relationship best describes the sequence of operations?
📖 Explanation: Each iteration first receives a client request via recvfrom, then immediately echoes it back with sendto, after which the loop repeats. The bind operation occurs only once before the loop, so the correct order is recvfrom followed by sendto.
Q7. If the server receives a datagram larger than sizeof(buffer), what is the most probable outcome?
📖 Explanation: recvfrom copies up to the size of the supplied buffer; any bytes beyond that are silently dropped. It does not cause a crash nor resize the buffer, and it still returns the number of bytes copied, making option A correct.
Q8. Consider two UDP echo servers: one uses a fixed‑size buffer, the other dynamically allocates a buffer based on the incoming datagram size. Which analytical comparison is most accurate?
📖 Explanation: A dynamically sized buffer matches the exact datagram length, minimizing unused space, yet each recvfrom incurs malloc/free overhead. Fixed buffers avoid allocation cost but may waste memory or truncate data. Hence option A captures the trade‑off accurately.
Q9. How does the use of a separate clntAddrLen variable affect the reliability of the recvfrom call?
📖 Explanation: clntAddrLen is passed by reference; recvfrom updates it with the actual size of the client’s address. This allows the program to know precisely how many bytes of address information were filled, which is essential for correct subsequent use of the address.
Q10. A developer replaces the blocking recvfrom with a non‑blocking version and adds a sleep(1) inside the loop. Which logical consequence is most likely?
📖 Explanation: Non‑blocking recvfrom returns immediately if no data is present, causing the loop to iterate rapidly. Adding sleep(1) reduces the busy‑wait but still results in periodic polling, increasing overall CPU usage compared to a true blocking call. Hence option A reflects the most plausible effect.
Q11. When evaluating error handling, why is it important to check the return value of bind before entering the main loop?
📖 Explanation: If bind fails, the socket is not associated with any local address, so any subsequent recvfrom or sendto operations will fail. Early detection prevents the server from entering an infinite loop that cannot serve clients, making option A the correct evaluation.
Q12. Which conceptual principle explains why UDP does not require a listen or accept step before receiving data?
📖 Explanation: UDP operates without establishing a dedicated connection; therefore, a server can receive datagrams as soon as the socket is bound, without invoking listen or accept. This reflects the connectionless principle, making option A correct.
Q13. If the server inadvertently swaps the arguments of sendto and recvfrom, what deduction can be made about the program’s behavior?
📖 Explanation: Swapping the argument order violates the function prototypes, causing undefined behavior—most commonly a segmentation fault or immediate error return. The program will not function as intended, so option A is the logical deduction.
Q14. Analyzing the code, what is the effect of calling sizeof(clntAddr) instead of sizeof(struct sockaddr_in) when the address type is actually struct sockaddr_in?
📖 Explanation: Both clntAddr and struct sockaddr_in refer to the same type; therefore, sizeof(clntAddr) yields the exact size of the structure. No functional difference arises, making option A accurate.
Q15. Which logical reasoning best explains why the server uses an infinite loop after successful bind?
📖 Explanation: After binding, the socket is ready to receive datagrams. An infinite loop ensures the server remains active, handling each incoming request in turn. Re‑binding or closing would prevent further communication, so option A correctly captures the reasoning.
Q16. In a scenario where multiple clients send datagrams simultaneously, how does the UDP echo server handle concurrent requests?
📖 Explanation: UDP sockets deliver datagrams to the kernel queue; the server’s single‑threaded loop dequeues them one by one, effectively handling requests sequentially. No automatic threading or merging occurs, making option A the correct description.
Q17. Conceptually, why is the buffer declared as a static array rather than a pointer to dynamically allocated memory in this simple server?
📖 Explanation: A static array exists for the lifetime of the program, eliminating repeated allocation and deallocation costs. recvfrom can write directly into it without extra management, which is suitable for a simple echo server. Hence option A is correct.
Q18. If the server’s socket is created with the flag SO_REUSEADDR, what analytical impact does this have on successive runs of the program?
📖 Explanation: SO_REUSEADDR permits rebinding to the same address/port even when the previous socket is lingering in TIME_WAIT, facilitating rapid restarts. It does not affect error checking, port selection, or client connectivity, making option A the accurate analysis.
Q19. If the server mistakenly passes 0 as the length argument to sendto, what will be the outcome?
📖 Explanation: When the length parameter is zero, sendto sends zero bytes but still returns success (0). No payload reaches the client, yet the call does not crash. Therefore the correct outcome is described by option D.
Q20. Which analytical comparison best describes the error‑handling strategy used in the code snippet?
📖 Explanation: The code checks the return value of bind and perror; on failure it prints an error and exits, reflecting an immediate‑exit strategy rather than recovery, logging, or retrying. Hence option A accurately captures the approach.
Q21. How does the use of struct sockaddr as a generic address container aid the server’s portability?
📖 Explanation: struct sockaddr is a generic placeholder that can represent various protocol‑specific address structures (e.g., sockaddr_in, sockaddr_in6). By casting to this type, the code can operate on different families without modification, supporting portability. Thus option A is correct.
Q22. If the server wishes to limit the size of incoming datagrams to 512 bytes, which logical modification should be made?
📖 Explanation: recvfrom will still accept any datagram up to the buffer size, but the server can enforce a maximum by checking the returned length (len) and discarding or handling oversized packets. Therefore adding a post‑recv check (option C) is the logical solution.
Q23. Comparing UDP echo server to a TCP echo server, which statement is true regarding reliability?
📖 Explanation: UDP is connectionless and does not assure that datagrams arrive, arrive in order, or are not duplicated. TCP, by contrast, provides reliable, ordered delivery. Hence option A correctly contrasts the reliability aspects.
Q24. What can be inferred if the server prints an error from perror but continues execution?
📖 Explanation: perror only reports the current errno; it does not alter program flow. If execution continues after printing, it indicates the programmer deliberately ignored the error, making option A the valid inference.
Q25. Why is it unnecessary for the UDP server to call listen or accept before invoking recvfrom?
📖 Explanation: In the UDP model, binding makes the socket ready to receive datagrams. There is no concept of listening for connections or accepting them, which are TCP‑specific operations. Therefore option A explains the necessity.