🎓 BookMCQ
← Back to 27. Network Management

📝 MIB Management Information Base (21 MCQs)

📖 From Data Communication and Networks • 27. Network Management • 21 questions available

What is MIB Management Information Base?

A MIB is a virtual database that contains definitions of manageable objects on a network device, structured as a tree where each node has a unique OID and describes attributes like system name, interface status, or error counts that can be queried via SNMP.

6
Easy
9
Medium
6
Hard

📝 All MIB Management Information Base MCQs

Q1. What does the function htons()\text{htons}() do in line 15?

A.Convert host short to network byte order ✅
B.Convert host long to network byte order
C.Convert network short to host byte order
D.Perform no conversion
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The htons()\text{htons}() routine takes a 16‑bit value (the port number) in host byte order and swaps its bytes if necessary so that the result follows network byte order, which is big‑endian. This ensures that all machines interpret the port consistently regardless of their native endianness.

Q2. Which socket type is created by the call socket(PF_INET,SOCK_DGRAM,0)\text{socket}(PF\_INET, SOCK\_DGRAM, 0)?

A.TCP socket
B.UDP socket ✅
C.Raw socket
D.Listening socket
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The second argument SOCK_DGRAM\text{SOCK\_DGRAM} specifies a datagram‑oriented socket, which is the hallmark of UDP. Therefore the call creates a UDP socket, suitable for connectionless communication, as opposed to a stream‑oriented TCP socket.

Q3. If recvfrom()\text{recvfrom}() returns a negative value, what is the most likely immediate effect in the given code?

A.The server will terminate
B.The error will be ignored and the loop continues ✅
C.An error message will be printed by perror\text{perror}
D.The buffer will contain garbage data
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The code stores the return value of recvfrom()\text{recvfrom}() in *len* but does not test it for negativity. Consequently, when a negative value is returned, the program proceeds without reporting the error, effectively ignoring the failure and continuing the infinite loop.

Q4. Suppose the client sends a packet larger than the server's buffer size. What will happen when recvfrom()\text{recvfrom}() is called?

A.The packet will be truncated to the buffer size ✅
B.recvfrom\text{recvfrom} will fail with EMSGSIZE\text{EMSGSIZE}
C.The server will block until a smaller packet arrives
D.The extra bytes will be stored for the next recvfrom\text{recvfrom} call
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When the incoming datagram exceeds the length supplied to recvfrom()\text{recvfrom}(), the kernel copies only as many bytes as fit into the buffer and discards the remainder. The call succeeds, returning the number of bytes actually placed in the buffer, which is the truncated size.

Q5. What is the effect of calling \text{memset}(&servAddr, 0, sizeof(servAddr)) before setting fields?

A.It zeroes the structure, preventing garbage values ✅
B.It allocates memory for the structure
C.It sets the address family to AF_INET\text{AF\_INET}
D.It binds the socket automatically
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: memset\text{memset} fills the entire memory region of *servAddr* with zeros, ensuring that any fields not explicitly assigned later contain a known value (zero). This eliminates the risk of residual data from previous stack usage influencing the socket address configuration.

Q6. If the server's bind\text{bind} call fails because the port is already in use, which function will report the error?

A.perror\text{perror}
B.printf\text{printf}
C.fprintf\text{fprintf}
D.write\text{write}
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The code checks the return value of bind\text{bind} and, upon failure, invokes perror\text{perror} with the message \Error: bind failed!\. perror\text{perror} prints the supplied string followed by a description of the current errno\text{errno} value, thereby informing the user why the bind could not succeed.

Q7. Consider that the server runs inside an infinite for(;;)\text{for}(;;) loop. If the client sends a malformed packet that does not contain a null terminator, how will the server's sendto\text{sendto} behave?

A.It will send the exact number of bytes received ✅
B.It will append a null byte before sending
C.It will cause undefined behavior due to missing terminator
D.It will reject the packet
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: sendto\text{sendto} transmits the raw byte count specified by *len*, which is the number of bytes returned by recvfrom\text{recvfrom}. Because UDP does not rely on null‑terminated strings, the absence of a terminator does not affect transmission; the server simply forwards the same byte sequence it received.

Q8. Compare the use of bind()\text{bind}() in this UDP server with using connect()\text{connect}() on a TCP server. Which statement is true?

A.bind\text{bind} assigns a local address ✅
B.bind\text{bind} establishes a connection
C.bind\text{bind} is unnecessary for UDP
D.bind\text{bind} also performs a handshake
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: In both UDP and TCP, bind\text{bind} is used to associate a socket with a specific local IP address and port. It does not create a connection; rather, it reserves the address so the operating system knows where to deliver incoming packets. For TCP, a subsequent listen\text{listen} and accept\text{accept} are required to establish connections.

Q9. Which of the following best differentiates recvfrom()\text{recvfrom}() from recv()\text{recv}() in the context of this program?

A.recvfrom\text{recvfrom} provides source address information ✅
B.recv\text{recv} provides source address information
C.recvfrom\text{recvfrom} works only with TCP sockets
D.recvfrom\text{recvfrom} automatically acknowledges receipt
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: recvfrom\text{recvfrom} returns not only the payload but also fills a sockaddr structure with the sender's address and port, which is essential for a connectionless UDP server that must know where to send a response. In contrast, recv\text{recv} is used with connected sockets where the peer's address is already known.

Q10. Evaluate why the server uses sizeof(clntAddr)\text{sizeof(clntAddr)} in the sendto\text{sendto} call instead of clntAddrLen\text{clntAddrLen}.

A.Because the size is known at compile time
B.Because clntAddrLen\text{clntAddrLen} may be uninitialized
C.Because sendto\text{sendto} requires the exact structure size ✅
D.Because using clntAddrLen\text{clntAddrLen} would cause a runtime error
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The third argument of sendto\text{sendto} expects the length of the address structure, which for IPv4 is a constant sizeof(struct sockaddr_in)\text{sizeof(struct sockaddr\_in)}. Providing this compile‑time constant avoids reliance on a variable that might have been altered elsewhere, ensuring the kernel receives a correctly sized address block.

Q11. Suppose the server is modified to call listen()\text{listen}() after bind\text{bind}. What effect would this have on the UDP socket's behavior?

A.listen\text{listen} is ignored for UDP sockets
B.listen\text{listen} converts the socket to TCP
C.listen\text{listen} causes an error because the socket is not stream‑oriented ✅
D.listen\text{listen} enables a backlog queue for UDP
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The listen\text{listen} system call is defined only for stream‑oriented (SOCK\_STREAM) sockets. Invoking it on a datagram socket (SOCK_DGRAM\text{SOCK\_DGRAM}) results in an error, typically ENOTSOCK\text{ENOTSOCK} or EINVAL\text{EINVAL}, and the socket remains a UDP socket with no listening semantics.

Q12. If the server wishes to support multiple ports simultaneously, which design change is most appropriate?

A.Create multiple sockets each bound to a different port ✅
B.Use select()\text{select}() on a single socket
C.Change the socket type to SOCK_STREAM\text{SOCK\_STREAM}
D.Use setsockopt\text{setsockopt} to enable port reuse
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The simplest and most reliable method is to create a distinct socket for each port and bind each one separately. This isolates traffic per port, avoids complex multiplexing logic, and aligns with the UDP model where each socket is bound to a single local port.

Q13. Apply the principle of least privilege: which permission should the server binary ideally have?

A.Root privileges
B.Setuid root
C.Ordinary user privileges ✅
D.Group write permission
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Running the server under a regular, non‑privileged user account limits the potential impact of bugs or compromises. The process only needs permission to open a UDP socket on a non‑reserved port, which an ordinary user can do, thereby adhering to the security best practice of granting the minimum necessary rights.

Q14. Explain the relationship between INADDR_ANY\text{INADDR\_ANY} and the server's ability to receive packets from any network interface.

A.INADDR_ANY\text{INADDR\_ANY} binds to all interfaces ✅
B.INADDR_ANY\text{INADDR\_ANY} binds to the loopback interface only
C.INADDR_ANY\text{INADDR\_ANY} restricts to a single interface
D.INADDR_ANY\text{INADDR\_ANY} disables receiving
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When the server sets servAddr.sin_addr.s_addr = htonl(INADDR_ANY)\text{servAddr.sin\_addr.s\_addr = htonl(INADDR\_ANY)}, it tells the kernel to accept incoming datagrams on any local interface that has the specified port. This allows the program to listen on Ethernet, Wi‑Fi, or any other network device without needing separate bindings.

Q15. Synthesize how the combination of htons()\text{htons}() and htonl()\text{htonl}() ensures correct communication across heterogeneous systems.

A.They convert values to network byte order ✅
B.They encrypt the data
C.They compress the data
D.They validate the checksum
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Both functions translate host‑order integers to the standardized network byte order (big‑endian). htons()\text{htons}() handles 16‑bit quantities such as ports, while htonl()\text{htonl}() processes 32‑bit values like IP addresses. This uniform representation guarantees that machines with differing native endianness interpret the transmitted fields consistently.

Q16. Given the infinite loop, what potential resource leak could occur if the server does not handle errors properly, and how can it be mitigated?

A.File descriptor exhaustion ✅
B.Memory leak of the buffer
C.CPU spin without sleep
D.Socket descriptor duplication
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: If errors from system calls like recvfrom\text{recvfrom} or sendto\text{sendto} are ignored, the loop may continue creating new sockets or failing to close existing ones, eventually exhausting the process's file descriptor limit. Proper error handling, including closing the socket on fatal failures and optionally exiting or restarting, prevents this leakage.

Q17. If the server needs to log each client's IP address, which field from clntAddr\text{clntAddr} should be used and how must it be converted for human readability?

A.clntAddr.sin_addr.s_addr\text{clntAddr.sin\_addr.s\_addr} with inet_ntoa()\text{inet\_ntoa}()
B.clntAddr.sin_family\text{clntAddr.sin\_family} with ntohs()\text{ntohs}()
C.clntAddr.sin_port\text{clntAddr.sin\_port} with ntohs()\text{ntohs}()
D.clntAddr.sin_addr.s_addr\text{clntAddr.sin\_addr.s\_addr} with ntohl()\text{ntohl}()
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The IPv4 address of the client resides in clntAddr.sin_addr.s_addr\text{clntAddr.sin\_addr.s\_addr}. To transform this binary value into the familiar dotted‑decimal notation, the program should call inet_ntoa()\text{inet\_ntoa}() (or the thread‑safe inet_ntop\text{inet\_ntop}). This yields a readable string suitable for logging.

Q18. Apply the concept of idempotence to the server's sendto\text{sendto} operation: under what condition does sending the same buffer multiple times not change the system state?

A.When the client discards duplicate packets
B.When the network guarantees exactly‑once delivery
C.When the payload is stateless ✅
D.When UDP provides reliability
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: If the data carried by the packet does not modify any external state—e.g., it is a read‑only query or a timestamp—the act of retransmitting the same bytes does not alter the overall system behavior. This satisfies idempotence because the outcome remains identical regardless of how many times the packet is sent.

Q19. Infer the outcome if the variable clntAddrLen\text{clntAddrLen} is not initialized before the first call to recvfrom()\text{recvfrom}().

A.recvfrom\text{recvfrom} may write beyond the structure
B.recvfrom\text{recvfrom} will fail with EINVAL\text{EINVAL}
C.The server will receive the correct address
D.The program may crash due to undefined length
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: recvfrom\text{recvfrom} expects *clntAddrLen* to contain the size of the address buffer. If the variable holds a random value, the kernel may treat it as an invalid length and return an error, typically setting errno\text{errno} to EINVAL\text{EINVAL}. The call therefore fails, and *len* becomes 1-1.

Q20. Evaluate the impact of changing the socket's protocol argument from 0 to IPPROTO_UDP\text{IPPROTO\_UDP} in the socket\text{socket} call.

A.No functional change ✅
B.It forces use of UDP only
C.It disables checksum calculation
D.It causes bind\text{bind} to fail
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When the socket type is SOCK_DGRAM\text{SOCK\_DGRAM}, the protocol field is ignored if set to 0, and the kernel automatically selects the appropriate protocol (UDP). Explicitly specifying IPPROTO_UDP\text{IPPROTO\_UDP} yields the same result, so the behavior of the socket remains unchanged.

Q21. Synthesize a scenario where using this UDP server design could lead to a security vulnerability, and propose a mitigation strategy.

A.Lack of authentication
B.Use of a fixed port number
C.No encryption of payload
D.All of the above ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: An unauthenticated UDP listener on a well‑known port can be exploited by malicious actors to inject arbitrary data, perform amplification attacks, or exfiltrate information. Mitigation includes adding application‑level authentication, rotating or randomizing ports, employing transport‑level encryption (e.g., DTLS), and implementing rate‑limiting to reduce abuse.

🔗 Related Topics (MCQs)