tshark抓包源码分析&简介

1、Dumpcap不停的抓数据

capture_loop_start 启动子线程 pcap_read_handler一直读取

    if (use_threads) {

        pcap_queue = g_async_queue_new();

        pcap_queue_bytes = 0;

        pcap_queue_packets = 0;

        for (i = 0; i < global_ld.pcaps->len; i++) {

            pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);

#if GLIB_CHECK_VERSION(2,31,0)

            /* XXX - Add an interface name here? */

            pcap_opts->tid = g_thread_new("Capture read", pcap_read_handler, pcap_opts);

#else

            pcap_opts->tid = g_thread_create(pcap_read_handler, pcap_opts, TRUE, NULL);

#endif

        }

    }

 

如上蓝色函数名称pcap_read_handler 表示写队列对应的读函数

 

pcap_read_handler(void* arg)

{

    pcap_options *pcap_opts;

    char          errmsg[MSG_MAX_LENGTH+1];

 

    pcap_opts = (pcap_options *)arg;

 

    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Started thread for interface %d.",

          pcap_opts->interface_id);

 

    while (global_ld.go) {

        /* dispatch incoming packets */

        capture_loop_dispatch(&global_ld, errmsg, sizeof(errmsg), pcap_opts);

    }

    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Stopped thread for interface

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值