首页
社区
课程
招聘
求助] 大虾们帮个忙啊!关于windowsAPI实现端口进程关联的程序[求助]
发表于: 2007-4-21 08:59 6978

求助] 大虾们帮个忙啊!关于windowsAPI实现端口进程关联的程序[求助]

2007-4-21 08:59
6978
D:\Program Files\Microsoft Visual Studio\MyProjects\SS1\1.cpp(67) : error C2065: 'unsinged' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\SS1\1.cpp(121) : error C2065: 'UdPExTable' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\SS1\1.cpp(132) : error C2065: 'GetIp' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\SS1\1.cpp(142) : error C2065: 'GetProcessNameFromPID' : undeclared identifier
Error executing cl.exe.

1.obj - 4 error(s), 0 warning(s)
小弟是在校学生 vc方面是相当的菜!上面几个问题解决不了了。。。希望各位大虾能多多帮忙啊~~先谢谢大家了!
下面是源代码:
我的联系方式:站内 或者xiaosong_000@126.com

#include <stdio.h>
#include <windows.h>
#include <iprtrmib.h>
#include "iphlpapi.h"
#pragma comment(lib, "ws2_32.lib")
#define HOSTNAMELEN 256
#define PORTNAMELEN 256
#define ADDRESSLEN HOSTNAMELEN+PORTNAMELEN
//结构定义
typedef struct tagMIB_TCPEXROW{
DWORD dwState; //tcp连接状态
DWORD dwLocalAddr; //本地ip地址
DWORD dwLocalPort; //打开本地端口
DWORD dwRemoteAddr; //远程ip地址
DWORD dwRemotePort; //远程端口号
DWORD dwProcessId; //进程标识
} MIB_TCPEXROW,*PMIB_TCPEXROW;
typedef struct tagMIB_TCPEXTABLE{
DWORD dwNumEntries;
MIB_TCPEXROW table[ANY_SIZE];
} MIB_TCPEXTABLE,*PMIB_TCPEXTABLE;
typedef struct tagMIB_UDPEXROW{
DWORD dwLocalAddr;//本地ip地址
DWORD dwLocalPort;//打开本地端口
DWORD dwProcessId;//进程标识
}MIB_UDPEXROW,*PMIB_UDPEXROW;
typedef struct tagMIB_UDPEXTABLE{
DWORD dwNumEntries;
MIB_UDPEXROW table[ANY_SIZE];
}MIB_UDPEXTABLE,*PMIB_UDPEXTABLE;
//函数声明
typedef DWORD (WINAPI *PALLOCATE_AND_GET_TCPEXTABLE_FROM_STACK)(
PMIB_TCPEXTABLE *pTcpTable,
BOOL bOrder,
HANDLE heap,
DWORD zero,
DWORD flags
);
typedef DWORD (WINAPI *PALLOCATE_AND_GET_UDPEXTABLE_FROM_STACK)(
PMIB_UDPEXTABLE *pUdpTable,
BOOL bOrder,
HANDLE heap,
DWORD zero,
DWORD flags
);
//定义函数事例入口指针,初始化null
static PALLOCATE_AND_GET_TCPEXTABLE_FROM_STACK
pAllocateAndGetTcpExTableFromStack=NULL;
static PALLOCATE_AND_GET_UDPEXTABLE_FROM_STACK
pAllocateAndGetUdpExTableFromStack=NULL;
static char TcpState[][32]={"???","CLOSED","LISTENING",
"SYN_SENT","SYN_RCVD",
"ESTABLISHED","FIN_WAIT1","FIN_WAIT2","CLOSE_WAIT",
"CLOSING","LAST_ACK","TIME_WAIT","DELETE_TCB"};
//辅助函数
PCHAR GetPort(unsigned int port,char* pPort)
{
sprintf (pPort, "%d", htons( (WORD) port ) );
return pPort;
}
PCHAR GetIP(unsigned int ipaddr,char* pIP)
{
unsinged; int nipaddr;
nipaddr=htonl(ipaddr);
sprintf(pIP,"%d.%d.%d.%d", (nipaddr>>24) & 0xFF,
(nipaddr>>16) & 0xFF,(nipaddr>>8) & 0xFF,
(nipaddr) & 0xFF);
return pIP;
}
//加载api
BOOL LoadAPI()
{
pAllocateAndGetTcpExTableFromStack=(PALLOCATE_AND_GET_TCPEXTABLE_FROM_STACK)
GetProcAddress( LoadLibrary("iphlpapi.dll"),"AllocateAndGetTcpExTableFromStack");
if (!pAllocateAndGetTcpExTableFromStack)
return FALSE;
pAllocateAndGetUdpExTableFromStack=
(PALLOCATE_AND_GET_UDPEXTABLE_FROM_STACK)
GetProcAddress( LoadLibrary("iphlpapi.dll"),
"AllocateAndGetUdpExTableFromStack");
if (!pAllocateAndGetUdpExTableFromStack)
return FALSE;
}
int main (int argc,char* argv[])
{
int nRetCode;
DWORD i;
WSADATA WSAData;
HANDLE hProcessSnap;
PMIB_TCPEXTABLE TCPExTable;
PMIB_UDPEXTABLE UDPExTable;
char szProcessName[MAX_PATH];
char szLocalName[HOSTNAMELEN],szRemoteName[HOSTNAMELEN];
char szRemotePort[PORTNAMELEN],szLocalPort[PORTNAMELEN];
char szLocalAddress[ADDRESSLEN],szRemoteAddress[ADDRESSLEN];
nRetCode=LoadAPI();
if (nRetCode==FALSE)
{
printf("Loadlibrary error!\n");
return 0;
}
if (WSAStartup(MAKEWORD(1,1),&WSAData))
{
printf("WSAStartup error!\n");
return 0;
}
nRetCode=pAllocateAndGetTcpExTableFromStack(&TCPExTable,TRUE,

GetProcessHeap(),2,2);
if (nRetCode)
{
printf("AllocateAndGetTcpExTableFromStack error!\n");
return 0;
}

nRetCode=pAllocateAndGetUdpExTableFromStack (&UdPExTable,TRUE,GetProcessHeap(),2,2);
if (nRetCode)
{
printf("AllocateAndGetUdpExTableFromStack error!\n");
return -1;
}
//GET TCP LIST
printf("%-6s%-22s%-22s%-11s%s\n","Proto","Local Address","Foreign Address","State","Process");
for(i=0;i<TCPExTable->dwNumEntries;i++)
;{
sprintf(szLocalAddress,"%s:%s",
GetIp (TCPExTable->table[i].dwLocalAddr,szLocalName),
GetPort (TCPExTable->table[i].dwLocalPort,szLocalPort)
);
sprintf(szRemoteAddress,"%s:%s",
GetIp(TCPExTable->table[i].dwRemoteAddr,szRemoteName),
GetPort(TCPExTable->table[i].dwRemotePort,szRemotePort)
);
printf("%-6s%-22s%-22s%-11s%s:%d\n","TCP",
szLocalAddress,szRemoteAddress,
TcpState[TCPExTable->table[i].dwState],
GetProcessNameFromPID(TCPExTable->table[i].dwProcessId),
TCPExTable->table[i].dwProcessId
);
}
//GET UDP LIST
for(i=0;i<UDPExTable->dwNumEntries;i++)
{
sprintf(szLocalAddress,"%s:%s",
GetIp(UDPExTable->table[i].dwLocalAddr,szLocalName),
GetPort(UDPExTable->table[i].dwLocalPort,szLocalPort)
);
sprintf(szRemoteAddress,"%s","*:*");
printf("%-6s%-22s%-33s%s:%d\n","UDP",
szLocalAddress,szRemoteAddress,
GetProcessNameFromPID(TCPExTable->table[i].dwProcessId)
);TCPExTable->table[i].dwProcessId

;}
WSACleanup();
return 0;
}

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 1852
活跃值: (504)
能力值: (RANK:1010 )
在线值:
发帖
回帖
粉丝
2
都是未定义标识
自己再好好检查下,那几个变量的单词是否写错

比如第一个,应该是unsigned
看到这个错误下面就懒的看了
2007-4-21 14:36
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
哦!
谢谢!一开始就看错了,对vc有点不感冒~,还以为结构或者定义错了呢,谢谢斑竹~~
2007-4-22 10:20
0
雪    币: 2134
活跃值: (14)
能力值: (RANK:170 )
在线值:
发帖
回帖
粉丝
4
GetProcessNameFromPID没有,其他误定义了
2007-4-22 12:38
0
游客
登录 | 注册 方可回帖
返回
//