?? rawethernet.cpp
字號:
//////////////////////////////////////////////////////////
// RawEthernet.cpp文件
#include <windows.h>
#include <winioctl.h>
#include <ntddndis.h>
#include <stdio.h>
#include "protoutils.h"
int main()
{
// 啟動服務
if(!ProtoStartService())
{
printf(" ProtoStartService() failed %d \n", ::GetLastError());
return -1;
}
// 打開控制設備對象
HANDLE hControlDevice = ProtoOpenControlDevice();
if(hControlDevice == INVALID_HANDLE_VALUE)
{
printf(" ProtoOpenControlDevice() failed() %d \n", ::GetLastError());
ProtoStopService();
return -1;
}
// 枚舉綁定的下層適配器
CPROTOAdapters adapters;
if(!adapters.EnumAdapters(hControlDevice))
{
printf(" Enume adapter failed \n");
ProtoStopService();
return -1;
}
// 創建一個原始封包(至少應為16個字節長)
BYTE bytes[] = {0xff,0xff,0xff,0xff,0xff,0xff, // 目的MAC地址
0x00,0x02,0x3e,0x4c,0x49,0xaa, // 源MAC地址
0x08,0x00, // 協議
0x01,0x02,0x03,0x04,0x05,0x06}; // 通常數據
// 打印出每個下層適配器的信息,發送數據
for(int i=0; i<adapters.m_nAdapters; i++)
{
char sz[256];
wsprintf(sz, "\n\n Adapter: %ws \n Symbolic Link: %ws \n\n ",
adapters.m_pwszAdapterName[i], adapters.m_pwszSymbolicLink[i]);
printf(sz);
CAdapter adapter;
adapter.OpenAdapter(adapters.m_pwszSymbolicLink[i]);
// 在此適配器上發送原始數據
int nSend = adapter.SendData(bytes, sizeof(bytes));
if(nSend > 0)
printf(" Packet sent: %d bytes \n", nSend);
else
printf(" Packet sent failed \n");
}
::CloseHandle(hControlDevice);
ProtoStopService();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -