什么是 pcap、pcap_t、errbuf[PCAP_ERRBUF_SIZE] [英] what is pcap, pcap_t, errbuf[PCAP_ERRBUF_SIZE]

查看:185
本文介绍了什么是 pcap、pcap_t、errbuf[PCAP_ERRBUF_SIZE]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 C 编程的新手.谁能告诉我什么是 errbuf[PCAP_ERRBUF_SIZE]、pcap、pcap_t 以​​及 pcap_lookupdev() 是如何工作的

Hi I am a newbie in C programming. Can anyone tell me what is errbuf[PCAP_ERRBUF_SIZE], pcap, pcap_t and how does pcap_lookupdev() work

    struct pcap_pkthdr header;
const unsigned char *packet;
char errbuf[PCAP_ERRBUF_SIZE];

char *device;
pcap_t *pcap_handle;

int i;
device = pcap_lookupdev(errbuf);

推荐答案

什么是 errbuf[PCAP_ERRBUF_SIZE]

what is errbuf[PCAP_ERRBUF_SIZE]

一些libpcap例程,如果失败,会将错误信息放入缓冲区,以便使用libpcap的程序可以向用户报告错误.pcap_lookupdev() 是这些例程之一;如果它返回NULL,这意味着它没有找到任何可以打开的设备,所以它会在errbuf中放入一条错误消息.

Some libpcap routines, if they fail, put an error message into a buffer, so that the program using libpcap can report the error to the user. pcap_lookupdev() is one of those routines; if it returns NULL, that means it didn't find any device that it could open, so it puts an error message into errbuf.

pcap

pcap"是一个名称,有时用于 libpcap 和 WinPcap,或者用于它(以及一些其他代码,例如 Wireshark)编写的捕获文件格式.

"pcap" is a name sometimes used for libpcap and WinPcap, or for the capture file format that it (and some other code, such as Wireshark) writes.

pcap_t

pcap_t 是用于从网络接口或从包含数据包的 pcap(或在较新版本的 libpcap 中为 pcap-ng)文件读取数据包的句柄.libpcap/WinPcap 例程,例如 pcap_open_live()pcap_open_offline() 返回一个 pcap_t,您可以从中读取数据包,例如 pcap_loop()pcap_dispatch()pcap_next()pcap_next_ex();在较新版本的 libpcap(但尚未在 WinPcap 中)中,您还可以通过调用 pcap_create() 获得 pcap_t,在该 pcap_t 上设置各种选项code>,然后使用 pcap_activate()激活"它,使其可用于捕获.

A pcap_t is a handle used to read packets from a network interface, or from a pcap (or, in newer versions of libpcap, pcap-ng) file containing packets. libpcap/WinPcap routines such as pcap_open_live() and pcap_open_offline() return a pcap_t from which you can read packets with routines such as pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex(); in newer versions of libpcap (but not yet in WinPcap), you can also get a pcap_t by calling pcap_create(), set various options on that pcap_t, and then "activate" it, making it available to capture on, with pcap_activate().

设备是什么意思

通常,设备是一个网络接口,例如 Linux 机器上的 eth0wlan0en0en1 在 Mac 上,在 BSD、Solaris、HP-UX、AIX 等上的各种其他名称,或在 Windows 上使用 WinPcap 的各种有点神秘的字符串.在某些平台上,libpcap 还可以让您捕获机器 USB 接口上的流量(原始 USB 流量 - 您也可以在 USB 网络接口上捕获,但这些就像常规网络接口一样).

Usually, a device is a network interface, such as eth0 or wlan0 on a Linux machine, en0 or en1 on a Mac, various other names on BSD, Solaris, HP-UX, AIX, etc., or various somewhat cryptic strings on Windows with WinPcap. On some platforms, libpcap may also let you capture traffic on your machine's USB interfaces (raw USB traffic - you could also capture on USB network interfaces, but those would just be like regular network interfaces).

这篇关于什么是 pcap、pcap_t、errbuf[PCAP_ERRBUF_SIZE]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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