0.
Written in document order.
Development environment: win10+vs2013.
Configuring the WINPCAP environment is not much to say. Direct to URL: http://blog.sina.com.cn/s/blog_57432f380101qh3n.html
The content is mostly a solution to function interpretation + problems encountered. Learning && alerting.
1. Get the adapter list
The purpose of getting the adapter is to obtain which adapters are available on the machine, and then choose which adapter to use to grab the package.
First, let's look at a data type, pcap_if/pcap_if_t, which is a list structure that stores all the adapters for this machine.
struct pcap_if { struct pcap_if *next; Char *name; Char *description; struct pcap_addr *addresses; bpf_u_int32 flags; struct
View Code
Note:
The first is a pcap_if linked list pointing to the next device interface;
The second is the actual name of the device, which is the name that the machine can recognize, for pcap_open_live () invocation;
The third is the text descriptor of the device, which is a text symbol that people can recognize, and possibly null.
The fourth one is an address pointer to the first pointer to a series of interfaces (PCAP_ADDR);
The fifth one is a flag bit, currently this flag bit is mainly not loopback equipment.
Then, the function that gets the list of adapters is:
int Char *struct pcap_rmauth *** * *char * errbuf;)
View Code
Note:
1.source can use the source set above and can also be used:pcap_src_file_string or pcap_src_if_ String, which is the file and interface strings, respectively. "file://" , "rpcap://" .
2.auth is the remote login information (Pcap_rmauth), with user name, password, type. Both the user name and password are character pointers, and the types are: Rpcap_rmtauth_null and rpcap_rmtauth_pwd. More for Bull.
The 3.alldevs is used to store the returned interface information. We want to define pcap_if_t *alldevsin advance, which is a linked list that stores interface information.
4.ERRBUF error message.
5. The return value of 0 is smooth;-1 means an error occurred.
Finally, release the device function:
void Pcap_freealldevs (pcap_if_t *alldevsp)
View Code
Frees memory.
Original code:
#defineWIN32#include"Pcap.h" voidMain () {pcap_if_t*alldevs, *D; inti =0; CharErrbuf[pcap_errbuf_size]; /*pcap_errbuf_size =256 defined in Pcap.h*/ if(PCAP_FINDALLDEVS_EX (pcap_src_if_string, NULL, &alldevs, errbuf) = =-1)/*This API is used to obtain a list of network cards*/{fprintf (stderr,"Error in Pcap_findalldevs:%s\n", ERRBUF); //errbuf parameter When an exception occurs, this parameter is Pcap populated with a 3 specific error string return; } /*Display the contents of the Response field for the list*/ for(d = Alldevs; D; d = d->next) {printf ("%d.%s,%s\n", ++i, d->name,d->addresses); if(d->description) {printf ("(%s) \ n", d->description); //System ("pause"); } Elseprintf ("(No description available) \ n"); } if(i = =0) {printf ("\nno Interfaces found! Make sure WinPcap is installed.\n"); return; } /*We don ' t need any more the device list. Free It*/Pcap_freealldevs (Alldevs); System ("Pause");}
View Code
WinPcap Programming (I.)