in Computer Networks edited by
11,155 views
34 votes
34 votes

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

  1. $\textsf{connect}$
  2. $\textsf{bind}$
  3. $\textsf{listen}$
  4. $\textsf{accept}$
in Computer Networks edited by
11.2k views

2 Comments

4
4

3 Answers

35 votes
35 votes
Best answer

(C) is answer $\textsf{listen}$ converts unconnected socket into passive $\textsf{connect}$ i.e it is waiting for request from client.

edited by

4 Comments

Focus on the words of the question and if you know the basics of the socket, it is easy to answer.

Unconnected active TCP socket into a passive socket.

"Unconnected" means till now no connection has been established.

"Active" means the socket has been created, and socket will become active only when it is binded to the local machine's IP and port address(in this case machine is server) using bind() system call.

"into a passive socket"-We already must have listened to these terms like passive(something in which no initiative is taken) and active(in which initiative is taken). Passive socket is one which is ready to accept the connections from the client.

So now, you call listen() system call on the server side which informs the transport layer that it is ready to accept connections from the clients.

So, combining all,

First, you must have called socket() to create the socket

then bind() to bind the IP address and port to this newly created socket and now this socket becomes active.

Now I want this to listen to client requests, so I call listen()

73
73
best ans ayush
2
2
Thanku Ayush sir
1
1
17 votes
17 votes
  1. connect
    This system call sends SYN packets — it does something, so active.
     
  2. bind
    This system call binds the local machine's IP and port address to the socket — it does something, so active.
     
  3. listen
    This system call just makes the machine wait for someone to send a SYN packet — clearly passive.
     
  4. accept
    This system call sends ACK in response to SYN packets — it does something, so active.

Option C

3 votes
3 votes

listen() marks the socket referred to by sockfd as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept(). Source: http://linux.die.net/man/2/listen

Answer:

Related questions