函数原型:
int pcap_findalldevs(pcap_if_t **, char *);
returns 0 on success and -1 on failure.
/*
* Item in a list of interfaces.
*/
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 */
};
typedef struct pcap_if pcap_if_t;
#include <pcap/pcap.h>
void CCapture::findDev()
{
char buf[1024];
pcap_if_t *allDev;
pcap_findalldevs(&allDev, buf);
for (pcap_if_t *pdev = allDev; pdev; pdev=pdev->next)
{
cout<<"@:"<<pdev->name<<endl;
}
pcap_freealldevs(allDev);
}
int main(int argc, char *argv[])
{
CCapture capt;
capt.findDev();
return 1;
}
g++ main.cpp capture.cpp -lpcap -o testcap