#include <windows.h>
#include <windowsx.h>
#include <ntddndis.h>
#include <ntddpack.h>
#include "packet32.h "
#include "stdio.h "
#define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
int main(int argc, char* argv[])
{
HINSTANCE hLibrary;
BOOLEAN bRtn,bRtn2,bRtn3;
FARPROC lpFunc;
hLibrary=LoadLibrary( "packet321.dll "); //加载DLL
LPADAPTER lpAdapter;
LPPACKET lpPacket;
TCHAR NameBuf[500]={ '0 '}; //存放网卡的名字
ULONG NameLength=500; //名字长度
ULONG Length; //数据的长度
DWORD errorcode;
UCHAR packetbuff[1514];
ULONG Filter=0;
UCHAR Address[6];
DWORD dwRtn = PacketGetAdapterNames(NameBuf,&NameLength);
//得到网卡名字放入NameBuf
lpAdapter = PacketOpenAdapter(NameBuf); //打开网卡,返回指针
if (!lpAdapter || (lpAdapter-> hFile == INVALID_HANDLE_VALUE))
{
errorcode = GetLastError();
printf( "Unable to open the driver, Error Code : %lx\n ",errorcode);
}
Filter = NDIS_PACKET_TYPE_PROMISCUOUS;
bRtn2 = PacketSetFilter(lpAdapter,Filter);
lpPacket = PacketAllocatePacket(lpAdapter);
PacketInitPacket(lpPacket,packetbuff,1514);
bRtn = PacketReceivePacket(lpAdapter,lpPacket,TRUE,&Length);
PacketFreePacket(lpPacket);
return 0;
}
注意:这个人漏掉了PacketSetBuff函数;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。