A UDP sender transmits three datagrams to a receiver, in order, carrying 600, 1200 and 300 bytes of payload. Assume all three arrive in order and none is lost. The receiver, on Linux, calls recvfrom() three times, each time with a 1024-byte buffer and no flags. Give the number of bytes the first call returns, the number of bytes the second call returns, and the number of payload bytes that are discarded and never delivered to the application. Answer each as an exact integer number of bytes.
Unlock full course notes by signing up
What a single recv returns on a TCP stream
A client opens a TCP connection and makes two calls, send(fd, a, 100, 0) followed immediately by send(fd, b, 200, 0), then waits for a reply without closing or shutting down its sending side. Both sends return their full counts. The server then makes a single blocking call recv(cfd, buf, 1024, 0) on the connected socket. Assume default socket options and that this receive call completes successfully. Which statement about that call's return value is correct?
Port number printed without ntohs
A client connects from source port 5000 to a server running on a little-endian x86 host. The server logs the client's port by printing the sin_port field of the sockaddr_in filled in by accept() as an unsigned 16-bit integer, but it forgets to call ntohs(). What number does the log show? Give your answer as an exact integer.
Resuming a partially submitted buffer
A client must submit a 9216-byte buffer to a connected nonblocking TCP socket. Its send loop starts with a zero-based byte offset of zero. Each call requests the entire unsent suffix, and the loop advances its offset only by a positive return value.
The first three calls have these outcomes:
The first send returns 2048.