Click here to Skip to main content
15,886,741 members
Articles / Desktop Programming / MFC

Enhance netstat

Rate me:
Please Sign up or sign in to vote.
4.64/5 (11 votes)
16 Nov 2003 137.4K   3.8K   36  
This article shows an implementation of the main TCP/UDP functions of the IP Helper API that is used to get info about active connections including the process attached to a connection.
// TCPTable.h: interface for the CTCPTable class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TCPTABLE_H__79B29239_E26B_11D6_B451_0030052162DB__INCLUDED_)
#define AFX_TCPTABLE_H__79B29239_E26B_11D6_B451_0030052162DB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "StdAfx.h"

class CTCPTable  
{
	public:
		CTCPTable();
		virtual ~CTCPTable();

	private:
		//vars
		static MIB_TCPTABLE* m_pTcpTable;
		static MIB_TCPTABLE_EX* m_pTcpTableEx;
		static BYTE* m_pBuff;
		static BYTE* m_pBuffEx;

		TCPTABLE m_tcpTab;

	private:
		//methods
		bool		GetMatchingConn(u_long ulRemAdr, u_short usLocPort, u_long* ulLocAdr, u_short* usRemPort);
		CString		Convert2State(DWORD dwState);
		void		Conn2Console(DWORD dwPid, \
								 CString strProcName, \
								 CString strLocAddress, \
								 u_short usLocalPort, \
								 CString strRemAddress, \
								 u_short usRemotePort);

	public:
		//methods
		DWORD		PrintTable(void);
		DWORD		PrintTableEx(void);
		u_int		GetRecordsNumber(void);		
		TCPTABLE	GetTableAtIndex(int nIndex);
		bool		KillConnection(u_long ulRemIP, u_short usLocalPort);
		
		bool		m_bEstb;
};

#endif // !defined(AFX_TCPTABLE_H__79B29239_E26B_11D6_B451_0030052162DB__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions