C++实例(使用iphlpapi的未公开函数)

C++实例(使用iphlpapi的未公开函数),第1张

C++实例(使用iphlpapi的未公开函数),第2张

# include
# include
# include
# pragma comment(lib," ws2 _ 32 . lib ")
# define address len hostname len PORTNAMELEN
char SZ process name[MAX _ PATH];
char SZ local name[256];
char SZ remote name[256];
char szRemotePort[256];
char szLocalPort[256];
char szLocalAddress[256];
char SZ remote address[256];
PCHAR GetPort(unsigned int port,char * pPort)
{
sprintf(pPort," %d ",htons((WORD)port));
退货支持;
}
PCHAR GetIp(unsigned int IP addr,char * pIP)
{
unsigned int ni paddr;
ni paddr = htonl(IP addr);
sprintf(pIP," %d.%d.%d.%d ",
(nipaddr >> 24) & 0xFF,
(nipaddr >> 16) & 0xFF,
(nipaddr >> 8) & 0xFF,
(nipaddr)& 0x ff);
返回pIP
}
int main(int argc,char * argv[])
{
int nRetCode;
DWORD I;
wsa data wsa data;
PMIB _ TCPEXTABLE TCPEXTABLE;
pAllocateAndGetTcpExTableFromStack =(PALLOCATE _ AND _ GET _ TCPEXTABLE _ FROM _ STACK)GetProcAddress(LoadLibrary(" iphlpapi . dll "),
" allocateandgettcpetextablefromstack ");
WSAStartup(MAKEWORD(1,1),& wsa data);
nret code = pallocateandgettcptextablefromstack(& TCPExTable,TRUE,GetProcessHeap(),2,2);
for(I = 0;I < TCPExTable--> dwNumEntries;i++)
{
sprintf(SZ local address," %s:%s ",
GetIp(TCP extable-> table[I])。dwLocalAddr,szLocalName),
get port(TCPExTable-> table[I]。dwLocalPort,szLocalPort));
sprintf( szRemoteAddress," %s:%s ",
GetIp(TCP extable-> table[I])。dwRemoteAddr,szRemoteName),
get port(TCP extable-> table[I]。dwRemotePort,szRemotePort));
printf(" %-22s %-22s %-11s % d \ n ",
szLocalAddress,szRemoteAddress,
TCP state[TCP extable-> table[I]。dwState],
TCPExTable->table[i]。dwProcessId
);
}
WSACleanup();
返回0;
}

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » C++实例(使用iphlpapi的未公开函数)

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情