int pcap_findalldevs_ex ( char * source, //The 'source' is a parameter that tells the function where the lookup has to be done and it uses the same syntax of the pcap_open(). //This source will be examined looking for adapters (local or remote) (e.g. source can be 'rpcap://' for local adapters or 'rpcap://host:port' for adapters on a remote host) or pcap files (e.g. source can be 'file://c:/myfolder/'). struct pcap_rmtauth * auth, //auth,: a pointer to a pcap_rmtauth structure. This pointer keeps the information required to authenticate the RPCAP connection to the remote host. This parameter is not meaningful in case of a query to the local host: in that case it can be NULL. pcap_if_t ** alldevs, //alldevs,: a 'struct pcap_if_t' pointer, which will be properly allocated inside this function. When the function returns, it is set to point to the first element of the interface list; each element of the list is of type 'struct pcap_if_t'. char * errbuf //errbuf,: a pointer to a user-allocated buffer (of size PCAP_ERRBUF_SIZE) that will contain the error message (in case there is one). )
·功能:获得已连接的网络适配器列表;(Create a list of network devices that can be opened with pcap_open(). )
·该函数返回一个 pcap_if 结构的链表, 每个这样的结构都包含了一个适配器的详细信息;
·pcap_if结构链表中:数据域 name 和 description 表示一个适配器名称和一个可以让人们理解的描述;
·errbuf:一旦发生错误,这个参数将会被libpcap写入字符串类型的错误信息;
- Returns:
- '0' if everything is fine, '-1' if some errors occurred. The list of the devices is returned in the 'alldevs' variable. When the function returns correctly, 'alldevs' cannot be NULL. In other words, this function returns '-1' also in case the system does not have any interface to list.
The error message is returned in the 'errbuf' variable. An error could be due to several reasons:
- libpcap/WinPcap was not installed on the local/remote host
- the user does not have enough privileges to list the devices / files
- a network problem
- the RPCAP version negotiation failed
- other errors (not enough memory and others).
- Warning:
- There may be network devices that cannot be opened with pcap_open() by the process calling pcap_findalldevs(), because, for example, that process might not have sufficient privileges to open them for capturing; if so, those devices will not appear on the list.
The interface list must be deallocated manually by using the pcap_freealldevs().
struct pcap_rmtauth{ int type //Type of the authentication required. char * username //Zero-terminated string containing the username that has to be used on the remote machine for authentication. char * password //Zero-terminated string containing the password that has to be used on the remote machine for authentication. };
typedef struct pcap_if pcap_if_t;
struct pcap_if { pcap_if * next //if not NULL, a pointer to the next element in the list; NULL for the last element of the list char * name //a pointer to a string giving a name for the device to pass to pcap_open_live() char * description //if not NULL, a pointer to a string giving a human-readable description of the device pcap_addr * addresses //a pointer to the first element of a list of addresses for the interface u_int flags //PCAP_IF_ interface flags. Currently the only possible flag is PCAP_IF_LOOPBACK, that is set if the interface is a loopback interface. };