下面是源代码以及错误提示:
#include
#include
#include
#include
#include
#include
struct ether_header
{
u_int8_t ether_dhost[6];
u_int8_t ether_shost[6];
u_int16_t ether_type;
};
void ethernet_protocol_packet_callback(u_char *argument, const struct pcap_pkthdr *packet_header, const u_char *packet_content)
{
int packet_size;
char error_buffer[LIBNET_ERRBUF_SIZE];
char *dev1_ = "eth9";
char *dev2_ = "eth8";
libnet_t *l;
static int k;
char *data;
u_int8_t len;
int ethernet_protocol_tag = 0;
u_short ethernet_type;
struct ether_header *ethernet_protocol;
u_int8_t *hardware_destination;
u_int8_t *hardware_source;
len = packet_header->len;
data = packet_content;
int i;
for(i=0;i<14;i++)
data++;
ethernet_protocol = (struct ether_header*)packet_content;
printf("Ethernet type is :\n");
ethernet_type = ntohs(ethernet_protocol->ether_type);
printf("%04x\n", ethernet_type);
hardware_source = ethernet_protocol->ether_shost;
hardware_destination = ethernet_protocol->ether_dhost;
printf("Mac Source Address is : \n");
printf("%02x:%02x:%02x:%02x:%02x:%02x\n", *hardware_source, *(hardware_source + 1), *(hardware_source + 2), *(hardware_source + 3),
*(hardware_source + 4), *(hardware_source + 5));
printf("Mac Destination Address is : \n");
printf("%02x:%02x:%02x:%02x:%02x:%02x\n", *hardware_destination, *(hardware_destination + 1), *(hardware_destination + 2), *(hardware_destination+ 3),
*(hardware_destination + 4), *(hardware_destination + 5));
if(k%2==0)
l = libnet_init(LIBNET_LINK, dev1_, error_buffer);
else
l = libnet_init(LIBNET_LINK, dev2_, error_buffer);
k++;
ethernet_protocol_tag = libnet_build_ethernet(
hardware_destination,
hardware_source,
ethernet_type,
data,
len-14,
l,
ethernet_protocol_tag );
packet_size = libnet_write(l);
printf("??
california 于 2014-05-26 11:49:03发表:
帮顶下