winpcap编程,在新建的类的头文件中加入packet32.h头文件后,出现大量的类型重定义错误(文件winsock2.h),怎么办

ludou 2002-08-24 11:39:55
在用winpcap编程的过程中,在新建的类的头文件中加入packet32.h头文件后,出现大量的类型重定义错误(winsock2.h),如:
d:\编程工具\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\WinSock2.h(109): error C2011: “fd_set” : “struct”


怎么办:下面是我的头文件:
------------------------------------------------------------------------
#pragma once

#include "Thread.h"
#include "Packet32.h"

//#define EPT_IP 0x0800 /* type: IP */
//#define EPT_ARP 0x0806 /* type: ARP */
//#define EPT_RARP 0x8035 /* type: RARP */
//#define ARP_HARDWARE 0x0001 /* Dummy type for 802.3 frames */
//#define ARP_REQUEST 0x0001 /* ARP request */
//#define ARP_REPLY 0x0002 /* ARP reply */

typedef struct arpPacket
{
unsigned char eh_dst[6]; /* destination ethernet addrress */
unsigned char eh_src[6]; /* source ethernet addresss */
unsigned short eh_type; /* ethernet pachet type */

unsigned short arp_hrd; /* format of hardware address */
unsigned short arp_pro; /* format of protocol address */
unsigned char arp_hln; /* length of hardware address */
unsigned char arp_pln; /* length of protocol address */
unsigned short arp_op; /* ARP/RARP operation */

unsigned char arp_sha[6]; /* sender hardware address */
unsigned long arp_spa; /* sender protocol address */
unsigned char arp_tha[6]; /* target hardware address */
unsigned long arp_tpa; /* target protocol address */
} ARPPACKET;

extern LPADAPTER;
extern LPPACKET;

// 发送ARP广播
class CThread_ARP_Broadcast :
public CThread
{
UINT m_uSendedPacketNum; // 已发送的ARP包的数目
UINT m_uFrequency; // 发送频率

LPADAPTER m_lpAdapter;
LPPACKET m_lpPacket;
char m_szPacketBuf[600];

// 工作线程,发送ARP包
virt DWORD ThreadMethod();

public:
CThread_ARP_Broadcast(void);
~CThread_ARP_Broadcast(void);

// 开始发送ARP包
int Begin(CString sAdapter, CString sSourceMACString, CString sSourceIP, UINT nFrequency);
// 设置发送频率
void SetFrequency(UINT uFrequency);
// 停止发送ARP包
void Stop(void);
// 返回已发送的ARP包的数目,用于统计或计算实际发送速度,每次调用,会把m_uSendedPacketNum 清零
UINT GetSendedPacketNum(void);
// 将格化化后的MAC(如:"00-01-02...")转变为ARP包需要的原始MAC
static int FormatedMac2Mac(CString sFormatedMac, CString& sMac);
};
...全文
524 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ksyou 2002-09-11
  • 打赏
  • 举报
回复
xuexi
MungBean 2002-08-27
  • 打赏
  • 举报
回复
看在同名的份上,提供一个偏方给你试试:
将stdafx.h中的include <afxsock.h>注释掉
在所有用到socket的cpp文件中include <afxsocket.h>
原来的初始化socket的代码要保留。
ludou 2002-08-27
  • 打赏
  • 举报
回复
还是不行呀。
kingzai 2002-08-26
  • 打赏
  • 举报
回复
try this:
#include "stdafx.h"
#include "Thread.h"
#include "Packet32.h"
#include"ntddndis.h"


ludou 2002-08-26
  • 打赏
  • 举报
回复
试了一下,不行。
#include <winsock2.h>
#include <afxwin.h> // MFC 核心和标准组件

----------------------
d:\编程工具\Microsoft Visual Studio .NET\Vc7\atlmfc\include\afxv_w32.h(18): fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
saucer 2002-08-26
  • 打赏
  • 举报
回复
Try to include winsock2.h _before_ including afxwin.h.

Or you could follow the following advice from the ws2chat sample:

"It is necessary to define _WIN32_WINNT as 0x0400 for the precompiler (e.g. cl -D_WIN32_WINNT=0x0400 ...) in order for WINDOWS.H to include WINSOCK2.H rather than the older winsock.h. This is done automatically by MAKEFILEs that include the win32.mak (provided here) and leave the TARGETOS unspecified."

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧