写了个小程序,自己打包循环发送ARP数据包,但是我用sniffer监测,却监测不到发送的包。
大家帮我看看分析一下,谢谢了。typedef struct _ETHeader        // 14字节的以太头
{
    UCHAR    dhost[6];    // 目的Mac
    UCHAR    shost[6];    // 源Mac
    USHORT    type;        // 下层协议类型 如IP(ETHERTYPE_IP)、ARP(ETHERTYPE_ARP)等
} ETHeader, *PETHeader;#define ARPOP_REQUEST 1
#define ARPOP_REPLY 2
typedef struct _ARPHeader    // 28字节的ARP头
{
USHORT    hrd;        //硬件地址空间,以太网中为ARPHRD_ETHER
USHORT eth_type;    // 以太网类型
UCHAR    maclen;        // MAC地址的长度,为6
UCHAR    iplen;        // IP地址的长度,为4
USHORT    opcode;        // 操作代码,ARPOP_REQUEST为请求,ARPOP_REPLY为响应
UCHAR    smac[6];    // 源MAC地址
UCHAR    saddr[4];    // 源IP地址
UCHAR    dmac[6];    // 目的MAC地址
UCHAR    daddr[4];    // 目的IP地址
} ARPHeader, *PARPHeader;void CMainDlg::OnSend() 
{
char* smac = new char[20];
char* dmac = new char[20];
char* sip = new char[20];
char* dip = new char[20];
char* psmac = new char[20];
char* pdmac = new char[20];
u_short opCode; m_wndsMac.GetWindowText(smac, 20);
m_wnddMac.GetWindowText(dmac, 20);
m_wndsIp.GetWindowText(sip, 20);
m_wnddIp.GetWindowText(dip, 20);
m_wndPsMac.GetWindowText(psmac, 20);
m_wndPdMac.GetWindowText(pdmac, 20);
if(m_nArpOpType == 0) {
opCode = ARPOP_REQUEST;
} else {
opCode = ARPOP_REPLY;
}
for(int i=0; i<1000; i++)
         SendARPPacket(smac,dmac,psmac,sip,pdmac,dip,opCode);
}int CMainDlg::SendARPPacket(char *smac, char *dmac, char *psmac, char *pshost, 
 char *pdmac, char *pdhost, unsigned short opCode)
{
u_char *smac_u = str2mac(smac);
u_char *dmac_u = str2mac(dmac);
u_char *psmac_u = str2mac(psmac);
u_char *pdmac_u = str2mac(pdmac);
u_char *pshost_u = new u_char[4]; 
str2ip(pshost,pshost_u);
u_char *pdhost_u = new u_char[4];
str2ip(pdhost,pdhost_u); return SendARPPack(smac_u, dmac_u, psmac_u, pshost_u, pdmac_u, pdhost_u, opCode);
}int CMainDlg::SendARPPack(u_char *smac, u_char *dmac, u_char *psmac, u_char *pshost, 
   u_char *pdmac, u_char *pdhost, unsigned short opCode)
{
u_char packet[42]; //info
ETHeader etHeader;
ARPHeader arpHeader; memcpy(etHeader.shost, smac,6);
memcpy(etHeader.dhost, dmac,6);
etHeader.type = 0x0608; arpHeader.hrd = 0x0100;
arpHeader.eth_type = 0x0008;
arpHeader.maclen = 6;
arpHeader.iplen = 4;
arpHeader.opcode = htons(opCode);
memcpy(arpHeader.smac, psmac, 6);
memcpy(arpHeader.saddr, pshost, 4);
memcpy(arpHeader.dmac, pdmac, 6);
memcpy(arpHeader.daddr, pdhost, 4); memcpy(packet, &etHeader, sizeof(etHeader));
memcpy(packet+sizeof(etHeader), &arpHeader, sizeof(arpHeader));

sendPack(packet,42); return 0;
}int CMainDlg::sendPack(u_char *pack, int len)
{
pcap_t *fp;
        char errbuf[PCAP_ERRBUF_SIZE];

if ((fp = pcap_open(dev->name, // name of the device
   65536, // portion of the packet to capture. It doesn't matter in this case 
   1, // promiscuous mode (nonzero means promiscuous)
  1000, // read timeout
           NULL,
  errbuf // error buffer
 )) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", errbuf);
return 2;
} /* Send down the packet */
if (pcap_sendpacket(fp, // Adapter
pack, // buffer with the packet
len // size
) != 0)
{
fprintf(stderr,"\nError sending the packet: \n", pcap_geterr(fp));
return 3;
} pcap_close(fp); return 0;
}