免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1725 | 回复: 4
打印 上一主题 下一主题

[网络] 我自己写得libpcap抓包,用libnet发送程序,无法运行,错误为 段错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-05-25 20:52 |只看该作者 |倒序浏览
我自己写得libpcap抓包,用libnet发送程序,但是编译通过以后,无法运行,错误为 段错误,我自己也按照网上说段错误的调试了,但是还是不知道怎么修改。

下面是源代码以及错误提示:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pcap.h>
#include <libnet.h>
#include <errno.h>


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("鍙戦

论坛徽章:
0
2 [报告]
发表于 2014-05-25 22:16 |只看该作者
没有人知道吗

论坛徽章:
3
午马
日期:2013-09-09 21:55:38天秤座
日期:2014-03-04 10:39:14午马
日期:2014-05-05 18:56:36
3 [报告]
发表于 2014-05-27 09:05 |只看该作者
你把你源代码重新粘下,你这有乱码

论坛徽章:
3
午马
日期:2013-09-09 21:55:38天秤座
日期:2014-03-04 10:39:14午马
日期:2014-05-05 18:56:36
4 [报告]
发表于 2014-05-27 09:05 |只看该作者
你把你源代码重新粘下,你这有乱码

论坛徽章:
3
午马
日期:2013-09-09 21:55:38天秤座
日期:2014-03-04 10:39:14午马
日期:2014-05-05 18:56:36
5 [报告]
发表于 2014-05-27 09:05 |只看该作者
回复 1# ierent168
你把你源代码重新粘下,你这有乱码


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP