1

Is there a command line tool in windows that lists all the socket options that are currently set on a tcp socket? I am looking for something that lists all tcp connections in a process, and for each connection shows me the socket options that are set.

I have one client application that has zero latency (when talking to a service), and another that has a 45ms latency - so I thought a comparison of the socket options set on the two applications might help me figure out what is wrong.

I am using resource monitor to see the latency for the tcp connections.

tcb
  • 4,408
  • 5
  • 34
  • 51

1 Answers1

1

Getting the list of TCP connections that belong to a given process is easy. GetTcpTable2(), GetTcp6Table2(), and GetExtendedTcpTable() all report owning process IDs for open TCP connections.

Getting the options that are set for a given process's open sockets, on the other hand, is not trivial.

There is no API that specifically returns a list of socket handles for a given process, so you have to manually enumerate kernel handles looking for open sockets for the desired process:

C++ Get Handle of Open Sockets of a Program

socket handles

Then you have to inject your own code into that process, such as with CreateRemoteThread(), and have the code either:

  1. duplicate the socket handles via WSADuplicateSocket() and pass them to your app so it can use WSASocket() to access them, such as to call getsockopt() on them.

  2. query the sockets directly for the desired info, and then pass that back to your app.

Either way, there is no API to retrieve a given socket's list of current options. You have to query every individual option one at a time.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770