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参数存放查找失败的信息。

最新文章

  1. JMM(java内存模型)
  2. JS - 柯里化
  3. js DOM Document类型
  4. PHP检测每一段代码执行时间
  5. fatal error: Invalid layout of preloaded class
  6. 伪Base16的构思和实现
  7. 网络接口 使用NSURLConnection完成Get和Post方法
  8. JavaScript的对象与Json
  9. npm安装
  10. tamcat的使用
  11. LeetCode第五十八题
  12. Shader 入门笔记(二) CPU和GPU之间的通信,渲染流水线
  13. python小猪蹄儿
  14. C博客第02次作业---循环结构
  15. [20180403]访问dba_autotask_task无输出问题.txt
  16. JavaSE-序列化和反序列化
  17. MySQL crash-safe replication(1)
  18. Druid连接池(四)
  19. Linux内核中断处理体系分析
  20. 20172305 2018-2019-1 《Java软件结构与数据结构》第一周学习总结

热门文章

  1. 使用JSTL 对在页面上对 0,0,1 的分割处理 forTokens
  2. JSONArray ja = JSONArray.fromObject(list);//特殊类 用于将list转化为JSON 数据并返回 out.print(ja);
  3. svn问题:在eclipse里面使用SVN,怎么实现版本回滚呢?
  4. HDU1402:A * B Problem Plus(FFT与大数乘法)
  5. hdu5475(线段树单点修改,统计区间乘积)
  6. Spring的Task任务
  7. bzoj 1103: [POI2007]大都市meg【dfs序+树状数组】
  8. 洛谷 P1606 [USACO07FEB]荷叶塘Lilypad Pond【spfa】
  9. bzoj 1007: [HNOI2008]水平可见直线【半平面交】
  10. 深入浅出索引--Mysql45讲笔记记录 打卡day3