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 2958: 代码填充--雨昕学画画

    2958: 代码填充--雨昕学画画 时间限制: 1 Sec  内存限制: 128 MB 提交: 156  解决: 102 题目描述 雨昕开始学画水彩画,老师给雨昕一个形状(Shape)类,雨昕在Sha ...

  2. 修改phpmyadmin中的默认超时时间

    phpmyadmin在使用过程中经常出现"登陆超时(1440秒未活动),请重新登录",很烦 解决方法如下: 第一步: 修改php.ini,找到 session.gc_maxlife ...

  3. 网站图片增强JS插件2.0(兼容IE&FF)

    网站图片增强JS插件2.0简单介绍:插件可以增强网站互动能力与外链建设,用户在欣赏图片的同时,把看好的图片直接制作成自己喜欢的样式后通过QQ等传播,增强外链建设,通过用户互动创造外链.(支持:放大缩小 ...

  4. SPOJ:Triple Sums(母函数+FFT)

    You're given a sequence s of N distinct integers.Consider all the possible sums of three integers fr ...

  5. python中coding:utf-8和setdefaultencoding区别

    这两个作用不一样, 1. # coding:utf-8 作用是定义源代码的编码. 如果没有定义, 此源码中是不可以包含中文字符串的.PEP 0263 -- Defining Python Source ...

  6. Bootstrap 面板

    基本的面板:<div class="panel panel-default"> <div class="panel-body"> 这是一 ...

  7. 【POJ - 1458】Common Subsequence(动态规划)

    Common Subsequence Descriptions: A subsequence of a given sequence is the given sequence with some e ...

  8. AOP切面通知

    需要用的基本的jar包: aopalliance-1.0.jaraspectj-1.6.8.jaraspectjweaver-1.6.8.jarcommons-logging-1.1.3.jarspr ...

  9. Linux下VIM配置以及常用快捷键

    一.VIM配置 在目录 /etc/vim下面,有个名为vimrc的文件,这是系统中公共的vim设置文件,对所有用户都有效.而在每个用户的主目录下,都能自己建立私有的设置文件,命名为:“.vimrc”. ...

  10. _bzoj1014 [JSOI2008]火星人prefix【Splay】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1014 天,写kth()时,把判断条件k <= siz[ch[x][0]]错写成了k & ...