(1)报文格式
(2)代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/ethernet.h>
#include <netpacket/packet.h>
#include <string.h>
#include <net/if.h>
#define SRC_MAC { 0x00,0x0C,0x29,0x6F,0x57,0xE7 }//源MAC地址
#define DEST_MAC { 0x00,0x0C,0x29,0xD3,0xD6,0xF7 }//目的MAC地址
struct arppacket
{
unsigned char dest_mac[ETH_ALEN];//接收方MAC
unsigned char src_mac[ETH_ALEN];//发送方MAC
unsigned short type; //0x0806是ARP帧的类型值
unsigned short ar_hrd;//硬件类型 - 以太网类型值0x1
unsigned short ar_pro;//上层协议类型 - IP协议(0x0800)
unsigned char ar_hln;//MAC地址长度
unsigned char ar_pln;//IP地址长度
unsigned short ar_