pcap是packet capture的缩写。意为抓包。

功能:查找所有网络设备

原型:int pcap_findalldevs_ex(char* source,  struct pcap_rmtauth *auth,  pcap_if_t** alldevs,   char* errbuf );

返回值:0表示查找成功。-1表示查找失败

参数说明:

source:

指定是本地适配器或者远程适配器

本地适配器:'rpcap://'

远程适配器:'rpcap://host:port'

抓包文件。'file://c:/myfolder/'.

Defined:

#define  PCAP_SRC_FILE_STRING   "file://"
  String that will be used to determine the type of source in use (file, remote/local interface). 
#define  PCAP_SRC_IF_STRING   "rpcap://"
  String that will be used to determine the type of source in use (file, remote/local interface). 

详细描述:

The formats allowed by the pcap_open() are the following:

  • file://path_and_filename [opens a local file]
  • rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol]
  • rpcap://host/devicename [opens the selected device available on a remote host]
  • rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
  • adaptername [to open a local adapter; kept for compability, but it is strongly discouraged]
  • (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged]

The formats allowed by the pcap_findalldevs_ex() are the following:

  • file://folder/ [lists all the files in the given folder]
  • rpcap:// [lists all local adapters]
  • rpcap://host:port/ [lists the devices available on a remote host]

Referring to the 'host' and 'port' paramters, they can be either numeric or literal. Since IPv6 is fully supported, these are the allowed formats:

  • host (literal): e.g. host.foo.bar
  • host (numeric IPv4): e.g. 10.11.12.13
  • host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
  • host (numeric IPv6): e.g. [1:2:3::4]
  • port: can be either numeric (e.g. '80') or literal (e.g. 'http')

Here you find some allowed examples:

  • rpcap://host.foo.bar/devicename [everything literal, no port number]
  • rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
  • rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
  • rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
  • rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
  • rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
  • rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
  • rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]

struct pcap_rmtauth的定义如下:

struct pcap_rmtauth
{
int type;
char *username;
char *password;
};

type:简要身份验证所需的类型。

username:用户名

password:密码

auth参数可以为NULL.

pcap_if_t的定义如下:

struct pcap_if {
struct pcap_if *next;
char *name; /* name to hand to "pcap_open_live()" */
char *description; /* textual description of interface, or NULL */
struct pcap_addr *addresses;
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
};

pcap_addr的定义如下:

struct pcap_addr {
struct pcap_addr *next;
struct sockaddr *addr; /* address */
struct sockaddr *netmask; /* netmask for that address */
struct sockaddr *broadaddr; /* broadcast address for that address */
struct sockaddr *dstaddr; /* P2P destination address for that address */
};

bpf_u_int32的定义如下:

typedef unsigned int    u_int;

typedef    u_int bpf_u_int32;

struct sockaddr的定义如下:

struct sockaddr {
u_short sa_family; /* address family */
char sa_data[]; /* up to 14 bytes of direct address */
};

alldevs参数用于存放获取的适配器数据。如果查找失败,alldevs的值为NULL.

errbuf参数存放查找失败的信息。

详解 pcap_findalldevs_ex的更多相关文章

  1. Linq之旅:Linq入门详解(Linq to Objects)

    示例代码下载:Linq之旅:Linq入门详解(Linq to Objects) 本博文详细介绍 .NET 3.5 中引入的重要功能:Language Integrated Query(LINQ,语言集 ...

  2. 架构设计:远程调用服务架构设计及zookeeper技术详解(下篇)

    一.下篇开头的废话 终于开写下篇了,这也是我写远程调用框架的第三篇文章,前两篇都被博客园作为[编辑推荐]的文章,很兴奋哦,嘿嘿~~~~,本人是个很臭美的人,一定得要截图为证: 今天是2014年的第一天 ...

  3. EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解

    前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...

  4. Java 字符串格式化详解

    Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...

  5. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  6. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

  7. Git初探--笔记整理和Git命令详解

    几个重要的概念 首先先明确几个概念: WorkPlace : 工作区 Index: 暂存区 Repository: 本地仓库/版本库 Remote: 远程仓库 当在Remote(如Github)上面c ...

  8. Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...

  9. Node.js npm 详解

    一.npm简介 安装npm请阅读我之前的文章Hello Node中npm安装那一部分,不过只介绍了linux平台,如果是其它平台,有前辈写了更加详细的介绍. npm的全称:Node Package M ...

随机推荐

  1. YTU 2911: 我想放假

    2911: 我想放假 时间限制: 1 Sec  内存限制: 128 MB 提交: 124  解决: 46 题目描述 小明的弟弟上小学了,每次刚入学就想知道什么时候放假,但是每学期开学的日子和每学期的有 ...

  2. 【AHOI 2005】 约数研究

    [题目链接] 点击打开链接 [算法] 要求M,显然可以通过约数个数定理从1..N暴力计算答案,然而n最大10^6,这个算法的时间复杂度是 O(N * sqrt(N))的,不能通过此题 因此我们换一种思 ...

  3. EF通过反射追踪修改记录.适合记录变更系统

    private static void IsUpdate<T>(T old, T current, string id) { Model.PerFileHistory history = ...

  4. EF include 预先加载

    在asp.net mvc 中,常在控制器中预先加载导航属性,以便在视图中能够显示起关联的数据. 如果不预先加载,View中就会无法呈现外键的 关联数据. 会提示EF 错误发生. 一. 模型: publ ...

  5. glyphicon 图标的使用

    基本用法<span class="glyphicon glyphicon-search"></span>可以将图标放于按钮于链接中,一个大按钮,按钮的内容是 ...

  6. 洛谷 P4012 深海机器人问题 【最大费用最大流】

    和火星那个有点像,但是这个价值直接在路径上,不用拆点,对于每条价值为w的边(i,j),连接(i,j,1,w)(i,j,inf,0),表示价值只能取一次,然后连接源点和所有出发点(s,i,k,0),所有 ...

  7. Phpstorm安装和优化

    Phpstorm是php开发一个强大的IDE,但是它不是免费的需要注册码,而且界面是英文界面,对英文不太好的人有点不友好.所以这篇文章主要从phpstorm的破解和汉化来优化phpstorm. 1.首 ...

  8. [Usaco2008 Feb]Eating Together麻烦的聚餐

    Description 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的 ...

  9. (五)Python面向对象编程

    根据廖雪峰老师的python教程写一些学习总结! 面向对象编程 面向对象编程--Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元, ...

  10. 题解报告:hdu 1171 Big Event in HDU(多重背包)

    Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...