#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <linux/if.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#define IPV4_LENGTH 4
#define buffer_len 60 //ARP请求包大小为60B,,抓包时会抓到一些42B的包,这是抓包软件没有显示18B的Padding字段,Padding全0填充在包的末尾
/*ARP包结构*/
/*字段顺序不可更改,发包时是直接将buffer发出*/
struct arp_head{
uint16_t hardware_type; //硬件类型#1:Ethernet
uint16_t protocol_type; //协议类型#0x0800:IPv4
uint8_t hardware_size; //MAC地址长度#6
uint8_t protocol_size; //IP地址长度#4
uint16_t opcode; //ARP类型#1:request;2:reply
uint8_t sender_mac[ETH_ALEN]; //源MAC地址
uint8_t sender_ip[IPV4_LENGTH]; //源IP地址
uint8_t target_mac[ETH_ALEN]; //目标MAC地址
uint8_t target_ip[IPV4_LENGTH]; //目标IP地址
};
static void show_manual(int argc,char const *argv[]);
static int ip4str_parse(const char *point, unsigned char result[4]);
static int macstr_parse(const char *point, unsigned char result[6]);
static int parse_arg(int argc,char const *argv[],char *dev_name,uint8_t *dest_mac_addr,uint8_t *sender_ip,uint8_t *target_ip);
/******************************************************************************************/
int main(int argc, char const *argv[])
{
int i;
char dev_name[0x10];
uint8_t dest_mac_addr[6];
uint8_t sender_ip[4]; //ARP请求的源IP
uint8_t target_ip[4]; //ARP请求的目标IP
if(parse_arg(argc,argv,dev_name,dest_mac_addr,sender_ip,target_ip)){
show_manual(argc,argv);
exit
socket发送arp的工具
最新推荐文章于 2024-12-09 14:40:29 发布