Question

Which one of the following socket API functions converts an unconnected active TCP socket into a passive socket?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2014 answer key

Solution

Review BSD TCP socket API state transitions from active to passive endpoints.

  1. Socket Roles in TCP:

    • By default, a socket created by socket() is an active socket intended to initiate outgoing connections using connect().
    • A server process must convert its socket into a passive socket to wait for incoming connection requests.
  2. Function of listen():

    • The listen() system call takes an unbound or bound active socket and marks it as passive, indicating that the kernel should accept incoming connection requests directed to this socket and queue them.
    • The socket state transitions to the LISTEN state.
  3. Roles of other functions:

    • connect(): Initiates a three-way TCP handshake to a remote address (active).
    • bind(): Assigns a local IP address and port number to a socket, but does not make it passive.
    • accept(): Extracts the first completed connection request from the listen queue of a passive socket and returns a new connected descriptor.
Final answer

C

Common trap

Confusing bind() (assigns an address) or accept() (retrieves an established connection) with listen() (sets the socket to passive mode).

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

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 2
Question
34 of 65, printed as CS Q.24
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.