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期)