📝 SNMP SMI MIB components explained (18 MCQs)
📖 From Data Communication and Networks • 27. Network Management • 18 questions available
What is SNMP SMI MIB components explained?
SMI (Structure of Management Information) defines the rules for naming and structuring managed objects, while MIB (Management Information Base) is the actual database of these objects organized in a tree hierarchy, together enabling standardized representation and access to network device information in SNMP.
📝 All SNMP SMI MIB components explained MCQs
Q1. When the call to recv() returns -1, which of the following best describes the immediate effect in the program flow?
📖 Explanation: The recv() function returns –1 on error, causing the condition in the while statement to fail. Consequently the loop ends and the next statement after the loop is executed, which in this program is the error‑handling block that prints a message and calls exit(1). This behavior prevents any further processing of corrupted data.
Q2. What is the effect of the statement `maxLen -= n;` inside the receive loop?
📖 Explanation: Subtracting the number of bytes just received (n) from maxLen updates the remaining capacity of the buffer. This ensures that subsequent recv calls will not write past the allocated memory region, preserving safety and allowing the loop to stop when the buffer is full.
Q3. Why does the pointer `ptr` advance with `ptr += n;` before the server calls send()?
📖 Explanation: Each iteration adds the newly received bytes to the end of the buffer; moving the pointer forward keeps track of where the next bytes should be stored. When the loop finishes, the pointer points just past the last byte, and the accumulated length (`len`) accurately reflects the total data to be echoed back.
Q4. If the program omitted `close(s);` after sending the echo, which of the following is the most likely consequence?
📖 Explanation: Every successful accept creates a new socket descriptor. Without an explicit close, those descriptors remain open, consuming system resources. Over time the process can exhaust the per‑process file‑descriptor limit, causing subsequent accept or other socket calls to fail and preventing new client connections.
Q5. What could happen if the return value of `send(s, buffer, len, 0);` is not checked?
📖 Explanation: If send returns a value smaller than len, only part of the message reaches the client. Ignoring this return value means the server assumes the whole message was transmitted, leading to silent data loss and potentially confusing the client, which expects a complete echo.
Q6. How does the code segment that creates the listen socket (lines 23‑27) differ from the UDP socket creation segment (lines 6‑16) in terms of protocol semantics?
📖 Explanation: The TCP socket is created with the SOCK_STREAM type, which establishes a reliable, connection‑oriented channel. In contrast, the UDP example uses SOCK_DGRAM, which provides a connectionless, datagram‑oriented service. This fundamental difference dictates how data is exchanged and how errors are handled.
Q7. Evaluating the server’s current blocking socket calls, what is a primary drawback when handling many simultaneous client connections?
📖 Explanation: When the server uses blocking calls, it processes one client at a time on a single thread. Other clients attempting to connect must wait until the current connection is closed, which limits scalability and can cause noticeable latency under load.
Q8. Which of the following best differentiates the handling of a potential buffer overflow in this echo server from a server that uses a fixed‑size buffer without adjusting `maxLen`?
📖 Explanation: By decrementing maxLen after each recv, the program tells the kernel exactly how many bytes remain safe to store. A fixed‑size buffer that never updates its limit cannot prevent recv from overrunning the buffer, making the former approach a proactive safety measure.
Q9. The error handling pattern `perror(...); exit(1);` is used after socket creation failures. Compared with a pattern that logs the error and continues, which statement is more appropriate for a production server that must maintain high availability?
📖 Explanation: In a production environment, terminating the entire process on a single socket error can cause unnecessary downtime. Recording the error and attempting to continue (or restart the affected component) gives the service a chance to stay operational and recover from transient issues.
Q10. What is the purpose of the `listen(s, backlog);` call in the TCP echo server?
📖 Explanation: The listen function transforms a bound socket into a passive listening socket and sets the backlog parameter, which limits how many incomplete connection requests the kernel will queue before refusing new ones. This is essential for establishing TCP connections.
Q11. In the loop, the variable `len` is updated with `len += n;`. How does this relationship between `len` and `n` affect the subsequent `send` call?
📖 Explanation: Each recv returns the number of bytes read (n). Adding n to len accumulates the total bytes collected across iterations. When send is finally called, len tells the kernel exactly how many bytes to transmit, guaranteeing that the whole message is echoed back.
Q12. If you wanted to modify this echo server to handle multiple clients concurrently without creating new processes, which design change would be most effective?
📖 Explanation: Using non‑blocking sockets together with an event‑multiplexing mechanism such as select, poll, or epoll lets a single thread monitor many descriptors simultaneously. When a descriptor becomes readable or writable, the server can perform the appropriate I/O without blocking, thereby serving many clients at once.
Q13. How does explicitly calling `close(s);` after sending the echo contribute to resource management on the server?
📖 Explanation: Closing the socket releases the underlying file descriptor back to the operating system. This prevents descriptor exhaustion, frees kernel buffers associated with the connection, and ensures that subsequent accept calls can obtain fresh descriptors for new client sessions.
Q14. TCP guarantees ordered delivery of bytes. In the context of this echo server, which mechanism ensures that the client receives the echoed data in the same order it was sent?
📖 Explanation: TCP assigns a sequence number to each byte segment and requires the receiver to acknowledge them. If a segment arrives out of order, TCP buffers it until missing pieces are received, then delivers data to the application in the original order, guaranteeing that the echo appears exactly as it was transmitted.
Q15. Why must the server allocate and bind a local address before calling `listen`?
📖 Explanation: Binding ties the socket to a concrete network endpoint (IP address and port). The kernel uses this information to direct incoming SYN packets to the process that called bind, making it possible for listen to queue connection requests for that specific address.
Q16. Which function is used to create a new socket descriptor?
📖 Explanation: The socket() system call creates an endpoint for communication and returns a file descriptor that can be used in subsequent network operations such as bind, listen, accept, send, and recv.
Q17. The prototype for `recv` is defined in which header file?
📖 Explanation: All socket‑related functions, including recv, are declared in the <sys/socket.h> header, which provides the necessary type definitions and prototypes for low‑level network I/O on POSIX systems.
Q18. On successful execution, what does the `close` function return?
📖 Explanation: According to the POSIX specification, close returns 0 on success and –1 on error, setting errno to indicate the failure reason. The closed descriptor number is not returned; it is simply released.