CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Steve Hebert's Development Blog

Steve's Blog - From .Net to dotMath and everything in between.

TCPView and Close Connection - how'd he do that?

On my new project,  I've been helping to trace down problems with 3rd party/backend libraries exhibiting bad behaviors. 

In tracking down these behaviors, I've been using TCPView to watch connections and see how the application is behaving on the wire.  TCPView is a product written by Mark Russinovich and made available at SysInternals.com  that interactively displays active TCP connections.  If you've never spent an afternoon browsing through the utilities at SysInternals, you are way past due. Russinovich utilities have always had a cool factor where you inevitably go "I didn't know you could do that". In addition to being far more useful than NetStat, TCPView has one feature that is really compelling - "Close Connection".

This function gives me a thought - can I target an application for programmatic 'pulled-wire' testing without having to disconnect the wire on my box? 

Mark makes the code for his enhanced version of netstat - which he calls NetStatP - available for free, but he doesn't float up the implementation for Close Connection.  All of the other code I have rewritten in C#, now if I could just find Close Connection.... I've been digging in MSDN and Google, but without success. 

I wonder if his Close Connection implementation could be used to hound an application and close all of its open connections? 

BTW:  I'm late to the game on Russinovich's blog - subscribed!



Comments

Chris Taylor said:

I would not know how Mark is achieving this, but I know of a number of ways to close the connections. The simplest is to use SetTcpEntry from Iphlpapi.dll, set the members of the MIB_TCPROW structure to match the entry to be closed and set the dwState member to MIB_TCP_STATE_DELETE_TCB.
# November 4, 2005 6:02 PM

shebert said:

Thank you Chris!

I'll give this a try.

# November 8, 2005 10:46 AM
Check out Devlicio.us!

Our Sponsors