/*device_list.c*/
#include <stdio.h>
#include <pcap.h>
#include <string.h>
#include <stdlib.h>
pcap_t *fp[10];
void main()
{
/*获取单个设备信息,默认第一个设备名称*/
/*
char error_content[PCAP_ERRBUF_SIZE];
char *net_interface;
u_int32_t net_ip;
u_int32_t net_mask;
net_interface=pcap_lookupdev(error_content);
pcap_lookupnet(net_interface,
&net_ip,
&net_mask,
error_content);
printf("Network Interface is :%s\n",net_interface);
*/
/*获取设备列表信息*/
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0,j=0;
int length=0;
char errbuf[PCAP_ERRBUF_SIZE];
char temp_device[15]={0};
if((pcap_findalldevs(&alldevs,errbuf))==-1)
{
fprintf(stderr,"Errof in pcap_findalldevs_ex:%s/n",errbuf);
exit(1);
}
/*printf the device_list*/
for(d=alldevs;d!=NULL;d=d->next)
{
printf("\n%s\n",d->name);
}
pcap_freealldevs(alldevs);
}
编译命令: gcc -o deviceList device_list.c -lpcap