🎓 BookMCQ
← Back to 26. Standard Client Server Protocols

📝 Recursive vs iterative DNS resolution (15 MCQs)

Two Ways DNS Queries Obtain an Answer

DNS resolution can use recursive or iterative query behavior, describing how much work the queried server must perform. With recursion, a server is asked to obtain a final answer or report failure on the client's behalf. With iteration, a server returns the best information it has, often a referral to another name server. Its distributed structure avoids reliance on one central database for every Internet name worldwide.

Resolver Responsibilities and Referral Messages

A stub resolver commonly sends a recursive query to its configured recursive resolver. That resolver may perform iterative queries to root, TLD and authoritative servers. An authoritative server generally responds with data for its zone or a referral, rather than recursively searching the rest of the DNS hierarchy for the client.

Recursive Requests and Iterative Referrals

In recursive resolution, the queried server accepts responsibility for completing the lookup. In iterative resolution, the requester follows referrals by sending another query to a server named in the previous response. The DNS message's RD bit requests recursion, while the RA bit indicates whether the responding server supports recursion. The lookup process combines local caching with referrals across delegated administrative zones.

A Lookup Through Root, TLD and Authoritative Servers

A laptop asks its recursive resolver for www.example.com and sets recursion desired. If its cache is empty, the resolver queries a root server, receives a com referral, queries a com server, receives an example.com referral and finally asks an authoritative server for the A record. It returns the answer to the laptop.

Combining Recursive Clients with Iterative Server Queries

The client's interaction with a recursive resolver can be recursive even though the resolver's upstream work is iterative. This division reduces work on end devices and lets a resolver cache results. Authoritative servers focus on their own zones, while recursive resolvers provide broader lookup service for clients. This division supports scalable administration while keeping naming separate from packet forwarding.

Misunderstandings About Recursive DNS

'Recursive means a server asks itself repeatedly' does not describe the protocol; it means the server completes resolution for the requester. 'Every query from a client is iterative' is false because clients commonly request recursion. 'An authoritative server must contact the root for every answer' ignores its own zone data and caching or referral context.

Tracing Query Flags and Resolution Direction

In message examples, recognize RD as recursion desired and RA as recursion available. Draw the client-to-resolver recursive request separately from the resolver's iterative root-to-TLD-to-authority queries. Explain which device follows referrals and where the final answer is returned, and avoid assuming that all DNS participants perform the same role. Practice each lookup stage and match returned data to the requested record type.

DNS Resolution Mode Terms

  • Recursive query - Requests a complete answer from a server.
  • Iterative query - Allows referrals to guide further queries.
  • RD bit - Requests recursive service.
  • RA bit - Indicates recursion availability.
  • Referral - Points toward another name server.
  • Stub resolver - Sends queries to a DNS resolver.
5
Easy
7
Medium
3
Hard

📝 All Recursive vs iterative DNS resolution MCQs

Q1. Which function creates a UDP socket?

A.socket(PF_INET, SOCK_DGRAM, 0) ✅
B.socket(AF_INET, SOCK_STREAM, 0)
C.socket(PF_INET, SOCK_STREAM, 0)
D.socket(AF_INET, SOCK_DGRAM, 0)
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The UDP socket is created by calling socket with the domain PF_INET (or AF_INET), the type SOCK_DGRAM, and protocol 0. This combination selects the datagram service of IPv4. The other options specify either stream sockets or the wrong domain, which would not produce a UDP socket.

Q2. Why is a null character appended to the echoed message before printing?

A.To terminate the string for proper display ✅
B.To indicate end‑of‑file
C.To signal a network error
D.To reset the socket buffer
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Appending '\0' creates a C‑style string terminator, allowing functions like printf or puts to know where the text ends. Without it, the printing routine would continue reading beyond the intended message, potentially outputting garbage data. This step is purely for safe, readable debugging output.

Q3. Which statement best compares TCP and UDP regarding reliability?

A.TCP guarantees ordered delivery, UDP does not ✅
B.UDP guarantees ordered delivery, TCP does not
C.Both guarantee ordered delivery
D.Neither guarantees ordered delivery
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: TCP is connection‑oriented and provides sequencing, acknowledgments, and retransmission, ensuring that data arrives in order. UDP is connectionless and sends datagrams without such guarantees; packets may arrive out of order, be duplicated, or be lost. Therefore, only TCP offers reliable, ordered delivery.

Q4. What is the purpose of the htons function in the code snippet servAddr.sin_port = htons(servPort);?

A.Convert host byte order to network byte order for the port ✅
B.Convert network byte order to host byte order for the port
C.Encrypt the port number
D.Validate the port range
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Network protocols use big‑endian (network) byte order. htons (“host to network short”) transforms a 16‑bit port number from the host’s native ordering to network ordering, ensuring that the receiving side interprets the port correctly. Without this conversion, mismatched byte orders could cause connection failures.

Q5. If sendto returns -1, what can be logically inferred?

A.An error occurred during transmission ✅
B.The message was delivered successfully
C.The socket was closed automatically
D.The server responded with an ACK
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A return value of -1 from sendto indicates that the system call failed, typically setting errno to describe the problem (e.g., EACCES, ENOTCONN). It means the data was not transmitted, and the program should handle the error before proceeding.

Q6. How does the error‑handling block if ((s = socket(PF_INET, SOCK_DGRAM, 0) < 0)) affect program robustness?

A.It detects socket creation failure and exits gracefully ✅
B.It silently ignores failures
C.It retries socket creation indefinitely
D.It changes the socket type to TCP
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The conditional checks whether the socket call returned a negative descriptor, which signals failure. By invoking perror and exit(1), the program reports the issue and terminates, preventing subsequent undefined behavior. This defensive pattern improves robustness by ensuring resources are valid before use.

Q7. Why is it important to close the socket with close(s) before exiting the program?

A.It releases the file descriptor and frees associated resources ✅
B.It encrypts the transmitted data
C.It flushes pending TCP acknowledgments
D.It resets the network interface
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Closing the socket returns the file descriptor to the operating system, allowing other processes to reuse it and preventing resource leaks. For UDP, it also discards any pending datagrams. Failing to close may leave descriptors open, consuming kernel resources and potentially causing exhaustion in long‑running applications.

Q8. What would be the effect of omitting the null character when printing the echoed message?

A.Garbage characters may appear after the intended text ✅
B.The program would crash immediately
C.The message would be sent twice
D.The socket would be closed automatically
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Without a terminating '\0', printing functions treat the buffer as a C‑string and continue reading memory until a zero byte is encountered. This can result in extra, unintended characters being displayed, possibly exposing sensitive data or causing confusing output during debugging.

Q9. Compare send and sendto when used with UDP sockets. Which statement is accurate?

A.Both can transmit datagrams, but sendto requires destination address each call ✅
B.Only send works with UDP, sendto requires TCP
C.send automatically retries on loss, sendto does not
D.sendto adds encryption, send  does not
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When a UDP socket is unconnected, sendto allows specifying the target address with each call, while send can be used after a prior connect to fix the peer. Both functions place datagrams on the network; neither provides reliability or retransmission, which are intrinsic to TCP only.

Q10. How does the connection‑oriented nature of TCP influence the sequence of socket calls compared to UDP?

A.TCP requires connect before send/recv, UDP does not ✅
B.UDP requires connect before send/recv, TCP does not
C.Both require connect before any data transfer
D.Neither requires connect for data transfer
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: TCP establishes a reliable session via connect, which negotiates sequence numbers and flow control. After this handshake, send and recv operate on the established connection. UDP is connectionless; it can send datagrams directly with sendto without a prior connect, though an optional connect can set a default peer.

Q11. If the programmer forgets to apply htons to servPort, what is the most likely outcome?

A.The server will bind to an unintended port number ✅
B.The socket will automatically correct the order
C.The program will compile with a warning
D.The port number will be encrypted
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Omitting htons leaves the port in host byte order. On little‑endian machines this swaps the high and low bytes, causing the socket to bind to a different numeric port than intended. The server will then listen on the wrong port, and clients will fail to connect.

Q12. Why is printing the echoed message considered a useful debugging technique in this code?

A.It provides immediate visual confirmation of data integrity ✅
B.It encrypts the transmitted data
C.It reduces network latency
D.It automatically corrects protocol errors
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Displaying the received buffer lets the developer verify that the round‑trip transmission succeeded and that the content matches the original string. Any discrepancy, such as truncation or corruption, becomes apparent instantly, allowing quicker identification of logic or network issues during development.

Q13. When using sizeof(servAddr) versus sizeof(struct sockaddr_in) in the sendto call, what conceptual difference matters?

A.Both yield the same size, but using the explicit type clarifies intent ✅
B.The former yields a larger size causing buffer overflow
C.The latter yields a smaller size causing truncation
D.Only the explicit type works on Windows platforms
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: In this context servAddr is declared as struct sockaddr_in, so sizeof(servAddr) and sizeof(struct sockaddr_in) are identical. However, expressing the size with the explicit type makes the code clearer to readers and avoids accidental mismatches if the variable’s type changes in the future.

Q14. What logical consequence follows if the client specifies an incorrect servPort value?

A.The client’s packets will be directed to the wrong service or be dropped ✅
B.The server will automatically adjust the port
C.The operating system will correct the port number
D.The client will switch to TCP automatically
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Ports identify specific services on a host. Supplying an incorrect port means the datagrams are sent to a destination where no listening socket exists, leading to silent discarding by the network stack or reception by an unintended service, effectively causing communication failure.

Q15. Evaluate how the program would need to change to support multiple concurrent clients without altering the core logic. Which modification is essential?

A.Introduce a separate thread or process for each client ✅
B.Replace SOCK_DGRAM with SOCK_STREAM
C.Remove the null‑character insertion step
D.Hardcode the server IP address
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: To handle many clients simultaneously while keeping the existing UDP‑based logic, the program should spawn a new thread or process for each incoming request, allowing independent handling of messages. UDP itself already supports multiple clients, but concurrency requires parallel execution to avoid blocking on a single client.

🔗 Related Topics (MCQs)