如何使用pcap_breakloop? [英] How to use pcap_breakloop?

查看:2957
本文介绍了如何使用pcap_breakloop?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另外一个功能pcap_loop函数,即数据包捕获
直到用户停止它,即。

I have a pcap_loop function in another function, that captures packets until the user stops it, i.e.

void functionA()
{
   signal(SIGINT, terminate_process); 
   pcap_loop(handle, -1, callback, NULL);
   ...

}

void terminate_process(int signum)
{
   pcap_breakloop(handle);
   pcap_close(handle);
} 

是否可以设置当数据包将被捕获的持续时间?是这样的:

Is it possible to set a duration for when packets would be captured? Something like:

if (time(NULL) - start_time > 100)
   pcap_breakloop(handle);

但我不知道在哪里把这个,因为到目前为止,所有的例子我见过用pcap_breakloop在信号处理程序,它需要用户干预。如何将时间条件,而pcap_loop运行进行检查?

But I don't know where to put this, because so far all the examples I've seen used pcap_breakloop in a signal handler, which requires user intervention. How will the time condition be checked while pcap_loop is running?

感谢您。

问候,
莱恩

推荐答案

您可以使用的报警的一个给定的秒数后产生的信号:

You can use alarm to generate a signal after a given number of seconds:

void functionA()
{
    signal(SIGALRM, terminate_process); 
    alarm(100);
}

这篇关于如何使用pcap_breakloop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆