🎓 BookMCQ
← Back to 27. Network Management

📝 Accounting management in networking (9 MCQs)

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

What is Accounting management in networking?

Accounting management tracks resource usage by users or departments for billing, cost allocation, or capacity planning purposes, often recording data such as login times, bandwidth consumption, and service requests to support administrative and financial decisions.

3
Easy
4
Medium
2
Hard

📝 All Accounting management in networking MCQs

Q1. In the code snippet, if the call to accept() fails, which of the following statements best describes the subsequent program behavior?

A.The server continues to listen for new connections.
B.The program prints an error message, calls exit(1), and terminates. ✅
C.The server retries the accept call indefinitely.
D.The program ignores the error and proceeds to receive data.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When accept() returns a negative value, the conditional block executes perror, which writes an error to stderr, then exit(1) is called. This causes immediate termination of the process, preventing any further execution of the receive or send loops. Hence the server does not continue listening after a failed accept.

Q2. What does the recv() function return when data is successfully received?

A.The number of bytes sent by the client
B.Zero, indicating end‑of‑file
C.The number of bytes actually read into the buffer ✅
D.A negative error code
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: recv() returns the count of bytes placed into the supplied buffer for the current call. This value is stored in variable n and used to update pointers and lengths. A return of zero signals a graceful shutdown by the peer, while negative values indicate errors.

Q3. Which statement correctly contrasts TCP and UDP usage in an echo‑server context as illustrated by the code?

A.TCP guarantees ordered delivery and requires a connection handshake; UDP is connectionless and may reorder packets. ✅
B.TCP is faster because it does not perform error checking; UDP provides reliability through checksums.
C.Both protocols use the same socket API calls shown in the snippet.
D.UDP offers flow control, whereas TCP does not.
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: TCP’s stream‑oriented nature mandates a three‑way handshake (socket, bind, listen, accept) and ensures ordered, reliable delivery, which matches the echo server’s design. UDP, being datagram‑oriented, lacks these guarantees and would require different handling (e.g., recvfrom) without the accept/listen sequence.

Q4. To allow the server to handle multiple simultaneous clients using fork(), which modification is most appropriate?

A.Move the recv‑loop inside the for‑loop without forking.
B.Insert a fork() call immediately after a successful accept() and place the recv‑send logic in the child process.
C.Replace accept() with select() and keep a single process.
D.Add a while‑true loop around the entire code and remove close(s). ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Forking after a successful accept creates a child process dedicated to a single client, allowing the parent to return to accept new connections. The child handles the recv‑send sequence and then exits, while the parent continues listening, achieving concurrent client handling without altering the existing logic flow.

Q5. What is the effect of the statement ptr += n within the receive loop?

A.It resets the pointer to the start of the buffer for each iteration. ✅
B.It advances the pointer by n bytes so subsequent data is stored after previously received bytes.
C.It deallocates n bytes from the buffer.
D.It causes the pointer to point to an invalid memory region.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The expression ptr += n increments the pointer by the number of bytes just received, positioning it at the next free location in the buffer. This ensures that each subsequent recv() call appends data rather than overwriting earlier bytes, maintaining a continuous stream of received data.

Q6. If the variable maxLen is not reset after each recv() call, what risk does the code incur?

A.The server will accept unlimited connections.
B.The buffer may overflow because the recv() call could write beyond the allocated memory.
C.The program will never exit the receive loop.
D.The send() function will transmit zero bytes. ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: maxLen represents the remaining space in the buffer. Failing to decrement it appropriately (or resetting it) can cause recv() to think there is more space than actually exists, leading to writes past the buffer’s end. This overflow can corrupt memory, cause crashes, or expose security vulnerabilities.

Q7. Which approach best integrates a logging mechanism that records each client’s IP address and byte count without disrupting the existing flow?

A.Add a global file pointer and write to the log after every recv() call, ignoring errors.
B.Create a struct containing the client’s address and byte count, write the struct to a log file inside the child process after send(), and close the file descriptor. ✅
C.Insert printf statements throughout the code to display the information on the console.
D.Use syslog() only after the server shuts down to batch‑write all logs at once.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Embedding a struct that captures the client’s sockaddr_in data (obtained from accept()) and the total bytes transferred (len) allows precise logging. Writing this information to a file in the child process after the echo completes ensures that each connection’s details are recorded atomically, preserving the server’s responsiveness.

Q8. If the send() call were placed before the receive loop, using the current value of len, what would most likely occur?

A.The server would echo back the correct data received later.
B.The client would receive an empty or uninitialized buffer, leading to protocol mismatch.
C.The server would crash due to a null pointer. ✅
D.The send() would block indefinitely waiting for data.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Placing send() before any data is received means len remains at its initial value (typically zero). The call would attempt to transmit zero bytes, which may be interpreted as a closed connection or cause the client to wait indefinitely for data that never arrives, disrupting the echo protocol.

Q9. How does calling close(s) differ from shutdown(s, SHUT_RDWR) in the context of this echo server?

A.close(s) only disables reading, while shutdown disables both reading and writing. ✅
B.shutdown(s, SHUT_RDWR) terminates the socket descriptor for all processes, whereas close(s) affects only the current process.
C.shutdown(s, SHUT_RDWR) informs the peer that no more data will be sent or received, while close(s) simply releases the descriptor without notifying the peer.
D.Both functions are equivalent; they perform the same operation.
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: close(s) releases the file descriptor but does not explicitly signal the peer about the termination of communication. shutdown(s, SHUT_RDWR) sends a FIN to the peer, indicating that no further sends or receives will occur, which can be useful for graceful shutdowns in a protocol‑aware server.

🔗 Related Topics (MCQs)