arp
时间:2010-05-14 来源:空灵静世
/*
* main.c
*
* Created on: 2010-5-13
* Author: root
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <libnet.h>
int main(){
int packet_size;
libnet_t *l;
libnet_ptag_t protocol_tag;
char *device ="eth0";
char error_infomation[LIBNET_ERRBUF_SIZE];
char *destination_ip_str = "192.168.18.147";
char *source_ip_str = "192.168.18.106";
u_char hardware_source[6] = {0x01,0x02,0x03,0x04,0x05,0x07};
u_char hardware_destination[6] = {0x01,0x02,0x03,0x04,0x05,0x08};
u_long destination_ip ;
u_long source_ip;
destination_ip = libnet_name2addr4(l,destination_ip_str,LIBNET_DONT_RESOLVE);
source_ip = libnet_name2addr4(l,source_ip_str,LIBNET_DONT_RESOLVE);
l = libnet_init(LIBNET_LINK_ADV,device,error_infomation);
printf("ip:[%lu]:[%lu]\n",source_ip,destination_ip);
protocol_tag = libnet_build_arp(ARPHRD_ETHER,ETHERTYPE_IP,6,4,ARPOP_REQUEST,hardware_source,(u_int8_t *)&source_ip,
hardware_destination,
(u_int8_t *)&destination_ip,NULL,0,l,0);
protocol_tag = libnet_autobuild_ethernet(hardware_destination,ETHERTYPE_ARP,l);
packet_size = libnet_write(l);
libnet_destroy(l);
return 0;
}
* main.c
*
* Created on: 2010-5-13
* Author: root
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <libnet.h>
int main(){
int packet_size;
libnet_t *l;
libnet_ptag_t protocol_tag;
char *device ="eth0";
char error_infomation[LIBNET_ERRBUF_SIZE];
char *destination_ip_str = "192.168.18.147";
char *source_ip_str = "192.168.18.106";
u_char hardware_source[6] = {0x01,0x02,0x03,0x04,0x05,0x07};
u_char hardware_destination[6] = {0x01,0x02,0x03,0x04,0x05,0x08};
u_long destination_ip ;
u_long source_ip;
destination_ip = libnet_name2addr4(l,destination_ip_str,LIBNET_DONT_RESOLVE);
source_ip = libnet_name2addr4(l,source_ip_str,LIBNET_DONT_RESOLVE);
l = libnet_init(LIBNET_LINK_ADV,device,error_infomation);
printf("ip:[%lu]:[%lu]\n",source_ip,destination_ip);
protocol_tag = libnet_build_arp(ARPHRD_ETHER,ETHERTYPE_IP,6,4,ARPOP_REQUEST,hardware_source,(u_int8_t *)&source_ip,
hardware_destination,
(u_int8_t *)&destination_ip,NULL,0,l,0);
protocol_tag = libnet_autobuild_ethernet(hardware_destination,ETHERTYPE_ARP,l);
packet_size = libnet_write(l);
libnet_destroy(l);
return 0;
}
相关阅读 更多 +