Question

Consider socket API on a Linux machine that supports connected UDP sockets. A connected UDP socket is a UDP socket on which connect function has already been called. Which of the following statements is/are CORRECT?

I. A connected UDP socket can be used to communicate with multiple peers simultaneously.
II. A process can successfully call connect function again for an already connected UDP socket.

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2017 answer key

Solution

Recall the behavior and semantics of calling the connect() system call on an unconnected versus connected UDP socket in POSIX/Linux socket programming.

Analyze each statement regarding connected UDP sockets:

  • Statement I: Calling connect() on a UDP socket records the specified remote IP address and port in the socket data structure in the kernel. Once connected, all subsequent send() or write() calls transmit datagrams strictly to that designated peer, and the socket only filters and receives incoming packets originating from that peer. Thus, a connected UDP socket cannot communicate with multiple peers simultaneously. Statement I is INCORRECT.
  • Statement II: A process can call connect() again on an already connected UDP socket to change the peer address to a new destination, or to unconnect the socket by specifying an address family of AF_UNSPEC. Such subsequent connect() calls succeed. Statement II is CORRECT.

Therefore, statement II only is correct, matching option B.

Final answer

B

Common trap

Assuming connect() on a UDP socket establishes a TCP-like three-way handshake; it only associates a default destination peer within the local socket descriptor.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 2
Question
18 of 65, printed as CS Q.18
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.