🎓 BookMCQ
← Back to 27. Network Management

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

4
Easy
8
Medium
6
Hard

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

A.The while loop terminates and execution proceeds to send()
B.The program jumps to the error handling block and exits ✅
C.The variable n is set to zero and the loop continues
D.The socket is automatically closed
💡 Difficulty: easy | ✅ Correct: B

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

A.It increments the number of bytes sent
B.It resets the buffer pointer to the start
C.It reduces the total allowed bytes for future recv calls ✅
D.It clears the socket's receive queue
💡 Difficulty: medium | ✅ Correct: C

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

A.To ensure the buffer contains only the newly received data
B.To position the pointer at the end of the accumulated data for correct length calculation ✅
C.To free memory used by previous data
D.To reset the socket descriptor
💡 Difficulty: hard | ✅ Correct: B

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

A.The client will receive duplicate data
B.The server will leak file descriptors leading to exhaustion ✅
C.The server will automatically close the socket on program termination
D.The send operation will fail
💡 Difficulty: medium | ✅ Correct: B

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

A.The server might think the data was sent even if only a partial send occurred
B.The socket will be closed automatically
C.The program will crash due to null pointer
D.The receive loop will restart ✅
💡 Difficulty: hard | ✅ Correct: D

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

A.It uses SOCK_STREAM instead of SOCK_DGRAM, providing connection‑oriented communication
B.It binds to a different port number
C.It does not allocate memory for the address structure ✅
D.It calls recv instead of send
💡 Difficulty: easy | ✅ Correct: C

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

A.Each client must wait for the previous one to finish, reducing concurrency
B.Blocking calls improve throughput for multiple clients
C.The server can accept unlimited connections without resource limits
D.Blocking sockets automatically spawn new threads ✅
💡 Difficulty: medium | ✅ Correct: D

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

A.Adjusting `maxLen` prevents recv from writing beyond the allocated memory
B.Both approaches have identical safety guarantees ✅
C.Using a fixed buffer eliminates the need for pointer arithmetic
D.The overflow is handled by the operating system in both cases
💡 Difficulty: hard | ✅ Correct: B

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

A.Exiting immediately is preferable because it prevents undefined behavior
B.Logging and continuing allows the server to stay up and possibly recover ✅
C.Both patterns are equivalent in effect
D.Continuing without logging is best for performance
💡 Difficulty: medium | ✅ Correct: B

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

A.It marks the socket as passive and specifies the maximum number of pending connections
B.It sends a greeting message to the client
C.It closes the socket after use
D.It encrypts the data transmitted over the socket ✅
💡 Difficulty: easy | ✅ Correct: D

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

A.`len` resets to zero after each iteration
B.`len` determines the size of the receive buffer
C.`len` accumulates the total bytes received, ensuring the send transmits the entire message ✅
D.`len` is unrelated to the send operation
💡 Difficulty: medium | ✅ Correct: C

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

A.Replace the blocking `recv`/`send` calls with non‑blocking I/O and use `select` or `poll` to multiplex sockets ✅
B.Increase the size of the buffer to accommodate all clients
C.Call `listen` inside the while loop for each client
D.Remove the `close(s);` statement
💡 Difficulty: hard | ✅ Correct: A

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

A.It releases the file descriptor, preventing leaks and allowing the OS to reclaim the socket resources
B.It resets the buffer contents to zero
C.It encrypts the transmitted data
D.It signals the client to reconnect ✅
💡 Difficulty: medium | ✅ Correct: D

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

A.The server’s use of `ptr += n;` reorders the data
B.The `listen` backlog parameter sorts packets
C.The TCP sequence numbers and acknowledgment process enforce ordering ✅
D.The `recv` function automatically timestamps data
💡 Difficulty: hard | ✅ Correct: C

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

A.Binding associates the socket with a specific port and IP, enabling the kernel to route incoming connection requests to the correct process
B.Binding encrypts the data ✅
C.Binding increases the socket’s buffer size
D.Binding disables TCP flow control
💡 Difficulty: medium | ✅ Correct: B

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

A.socket() ✅
B.bind()
C.listen()
D.recv()
💡 Difficulty: easy | ✅ Correct: A

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

A.<sys/socket.h> ✅
B.<stdio.h>
C.<unistd.h>
D.<netinet/in.h>
💡 Difficulty: medium | ✅ Correct: A

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

A.0 ✅
B.-1
C.the closed descriptor number
D.the number of bytes closed
💡 Difficulty: hard | ✅ Correct: A

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

🔗 Related Topics (MCQs)