如何使用winpcap的api函数

fbiboss001 2005-09-13 10:37:29
我按照网上的教程,已经包含了这两个文件了,但是为什么还是一堆错误?提示这些API没有定义,还有

\packet32.h(208) : error C2079: 'IPAddress' uses undefined struct 'sockaddr_storage'
\packet32.h(209) : error C2079: 'SubnetMask' uses undefined struct 'sockaddr_storage'
\packet32.h(210) : error C2079: 'Broadcast' uses undefined struct 'sockaddr_storage'


#include "Packet32.h"
#pragma comment(lib, "Packet.lib")


char *AdapterDeviceName =GetCurAdapterName(); // 首先获得获得网卡名字
lpAdapter = PacketOpenAdapter(AdapterDeviceName); // 根据网卡名字打开网卡
lpPacket = PacketAllocatePacket(); // 给PACKET结构指针分配内存
PacketInitPacket(lpPacket, &ARPPacket, sizeof(ARPPacket)); //初始化PACKET结构指针
// 其中的ARPPacket就是我们先前填充的ARP包

PacketSetNumWrites(lpAdapter, 1); // 每次只发送一个包
PacketSendPacket(lpAdapter, lpPacket, true); // Send !!!!! ^_^
PacketFreePacket(lpPacket); // 释放资源
PacketCloseAdapter(lpAdapter)
...全文
476 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fbiboss001 2005-09-15
谢谢,再请问一下ARP包类型该怎么填 了?
还有这个函数是我自己瞎编的,不知道具体怎么弄啊?
原文件是这样的,BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);


PTSTR AdapterDeviceName;
PacketGetAdapterNames(AdapterDeviceName,(unsigned long*)255);
回复
kingzai 2005-09-15
#pragma comment(lib, "ws2_32.lib")
回复
fbiboss001 2005-09-15
包含这两个文件,是不是应该还有个DLL了???
#include "Packet32.h"
#pragma comment(lib, "Packet.lib")

提示下面的:

Linking...
MYARPDlg.obj : error LNK2001: unresolved external symbol __imp__htons@4
MYARPDlg.obj : error LNK2001: unresolved external symbol __imp__inet_addr@4
Debug/MYARP.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
回复
fbiboss001 2005-09-15
我对照网上的写的,可是为什么通不过啊?


// DLC Header
typedef struct tagDLCHeader
{
unsigned char DesMAC[6]; /* destination HW addrress */
unsigned char SrcMAC[6]; /* source HW addresss */
unsigned short Ethertype; /* ethernet type */
} DLCHEADER, *PDLCHEADER;

// ARP Frame
typedef struct tagARPFrame
{
unsigned short HW_Type; /* hardware address */
unsigned short Prot_Type; /* protocol address */
unsigned char HW_Addr_Len; /* length of hardware address */
unsigned char Prot_Addr_Len; /* length of protocol address */
unsigned short Opcode; /* ARP/RARP */
unsigned char Send_HW_Addr[6]; /* sender hardware address */
unsigned long Send_Prot_Addr; /* sender protocol address */
unsigned char Targ_HW_Addr[6]; /* target hardware address */
unsigned long Targ_Prot_Addr; /* target protocol address */
unsigned char padding[18];
} ARPFRAME, *PARPFRAME;

// ARP Packet = DLC header + ARP Frame
typedef struct tagARPPacket
{
DLCHEADER dlcHeader;
ARPFRAME arpFrame;
} ARPPACKET, *PARPPACKET;












// 开始填充各个字段
ARPPACKET ARPPacket; // 定义ARPPACKET结构体变量

memset(&ARPPacket, 0, sizeof(ARPPACKET)); // 数据包初始化

formatStrToMAC("DLC源MAC字符串",ARPPacket.dlcHeader.SrcMAC); // DLC帧头
formatStrToMAC("DLC目的MAC字符串",ARPPacket.dlcHeader.DesMAC);

formatStrToMAC("ARP源MAC字符串",ARPPacket.arpFrame.Send_HW_Addr); // 源MAC
ARPPacket.arpFrame.Send_Prot_Addr = inet_addr("srcIP"); // 源IP
formatStrToMAC("ARP目的MAC字符串",ARPPacket.arpFrame.Targ_HW_Addr); // 目的MAC
ARPPacket.arpFrame.Targ_Prot_Addr = inet_addr("desIP"); // 目的IP

ARPPacket.arpFrame.Opcode = htons((unsigned short)"arp包类型"); // arp包类型

// 自动填充的常量
ARPPacket.dlcHeader.Ethertype = htons((unsigned short)0x0806); // DLC Header的以太网类型
ARPPacket.arpFrame.HW_Type = htons((unsigned short)1); // 硬件类型
ARPPacket.arpFrame.Prot_Type = htons((unsigned short)0x0800); // 上层协议类型
ARPPacket.arpFrame.HW_Addr_Len = (unsigned char)6; // MAC地址长度
ARPPacket.arpFrame.Prot_Addr_Len = (unsigned char)4; // IP地址长度



PTSTR AdapterDeviceName;
PacketGetAdapterNames(AdapterDeviceName,(unsigned long*)255);
// 首先获得获得网卡名字
LPADAPTER lpAdapter = PacketOpenAdapter(AdapterDeviceName); // 根据网卡名字打开网卡
LPPACKET lpPacket = PacketAllocatePacket(); // 给PACKET结构指针分配内存
PacketInitPacket(lpPacket, &ARPPacket, sizeof(ARPPacket)); //初始化PACKET结构指针
// 其中的ARPPacket就是我们先前填充的ARP包

PacketSetNumWrites(lpAdapter, 1); // 每次只发送一个包
PacketSendPacket(lpAdapter, lpPacket, true); // Send !!!!! ^_^
PacketFreePacket(lpPacket); // 释放资源
PacketCloseAdapter(lpAdapter);


回复
kingzai 2005-09-14
GetCurAdapterName is self define function.
you should check winpcap api in its official website.
winpcap.polito.it/
回复
fbiboss001 2005-09-14
GetCurAdapterName这个函数在packet32.h根本就没有啊,请问该怎么解决了?
回复
oyljerry 2005-09-13
寻找一些这几个,看是否有文件没有包含对
回复
fbiboss001 2005-09-13
不是,是我自己想写一个简单的可以发送ARP包的小程序.
回复
lifengice0706 2005-09-13
如果是执行wpcap的例子,可按其中dox中的一个.txt文件所说,顺序执行4个bat即可。
回复
fbiboss001 2005-09-13

就是这个文件,为什么会提示这三个错误了?

\packet32.h(208) : error C2079: 'IPAddress' uses undefined struct 'sockaddr_storage'
\packet32.h(209) : error C2079: 'SubnetMask' uses undefined struct 'sockaddr_storage'
\packet32.h(210) : error C2079: 'Broadcast' uses undefined struct 'sockaddr_storage'
回复
相关推荐
发帖
网络编程
创建于2007-09-28

1.8w+

社区成员

VC/MFC 网络编程
申请成为版主
帖子事件
创建了帖子
2005-09-13 10:37
社区公告
暂无公告