🎓 BookMCQ
← Back to 26. Standard Client Server Protocols

📝 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.
9
Easy
11
Medium
5
Hard

📝 All DNS hierarchical name space MCQs

Q1. Which function is used to bind a socket to an address?

A.bind ✅
B.connect
C.listen
D.accept
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.Print a descriptive error message to stderr ✅
B.Terminate the program immediately
C.Send an error packet to the client
D.Allocate memory for the buffer
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.The client never sent a datagram ✅
B.The socket is non‑blocking
C.The server called bind incorrectly
D.The buffer size is too small
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.len equals the number of bytes received ✅
B.len is always zero
C.len contains the client’s IP address
D.len is the size of clntAddrLen
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.To ensure the entire address structure is transmitted ✅
B.Because sizeof(clntAddr) is always smaller
C.Because clntAddrLen is uninitialized
D.To avoid blocking the call
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.recvfrom → sendto → repeat ✅
B.sendto → recvfrom → repeat
C.bind → recvfrom → repeat
D.recvfrom → bind → repeat
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.The excess bytes are discarded ✅
B.The server crashes
C.The buffer is automatically resized
D.recvfrom returns an error code
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Dynamic allocation reduces memory waste but adds allocation overhead ✅
B.Fixed buffers always improve performance
C.Dynamic allocation prevents any packet loss
D.Fixed buffers guarantee security
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.It tells recvfrom the size of the address structure ✅
B.It determines the maximum datagram size
C.It stores the received data length
D.It configures socket timeout
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.CPU usage will increase due to busy‑waiting ✅
B.The server will stop receiving packets
C.Latency will decrease dramatically
D.The socket will close automatically
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.A failed bind means the socket cannot receive any datagrams ✅
B.bind errors are harmless and can be ignored
C.bind returns the number of clients connected
D.bind automatically retries on failure
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Connectionless communication model ✅
B.Reliability guarantees
C.Flow control mechanisms
D.Three‑way handshake
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.It will likely crash due to invalid parameters ✅
B.It will still echo correctly
C.It will send data to an uninitialized address
D.It will ignore the error and continue
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.Both evaluate to the same size, so no effect ✅
B.The size will be larger than needed
C.The size will be smaller, causing truncation
D.It changes the address family
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.It must continuously listen for new client datagrams ✅
B.It needs to re‑bind for each client
C.It wants to allocate a new socket each iteration
D.It aims to close the socket after one message
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.It processes them sequentially as they arrive ✅
B.It spawns a new thread for each client
C.It merges the datagrams into one response
D.It drops all but the first datagram
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Static allocation avoids the overhead of malloc/free for each iteration ✅
B.Dynamic allocation is illegal in C
C.Static buffers increase security
D.Pointers cannot be used with recvfrom
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.It allows the socket to bind even if the previous instance is in TIME_WAIT ✅
B.It disables error checking on bind
C.It forces the server to use a random port
D.It prevents any client from connecting
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.No data will be transmitted, though the call succeeds
B.The server will crash immediately
C.The client will receive a corrupted packet
D.sendto will return an error code ✅
💡 Difficulty: hard | ✅ Correct: D

📖 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?

A.Immediate exit on error vs. attempting recovery ✅
B.Logging errors then continuing
C.Ignoring errors completely
D.Retrying the failed operation indefinitely
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.It abstracts IPv4 and IPv6 address formats under a common type ✅
B.It forces the code to use only IPv4
C.It eliminates the need for socket creation
D.It automatically encrypts the address
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.Change sizeof(buffer) to 512 in the recvfrom call
B.Increase the socket buffer size to 1024
C.Add a conditional check after recvfrom ✅
D.Remove the bind call
💡 Difficulty: medium | ✅ Correct: C

📖 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?

A.UDP provides no guarantee of delivery, ordering, or duplication avoidance ✅
B.TCP guarantees no packet loss but may reorder packets
C.Both protocols guarantee delivery
D.UDP ensures in‑order delivery
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.The programmer chose to ignore the error condition ✅
B.The error was non‑fatal and automatically corrected
C.perror clears the error flag
D.The socket is automatically reopened
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.UDP sockets are already ready to receive after bind ✅
B.listen is only for client sockets
C.accept is used only with raw sockets
D.recvfrom internally calls listen
💡 Difficulty: easy | ✅ Correct: A

📖 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.

🔗 Related Topics (MCQs)