#include #include #include #include int main(int argc, char *argv[]){ char errbuf[PCAP_ERRBUF_SIZE+1]; pcap_if_t * j; pcap_findalldevs(&j, errbuf); printf("Accessible interfaces are:\n"); for(; j; j = j->next) {printf("network device name: %s, description: %s, \n", j->name, j->description); pcap_t* dev = pcap_open_live(j->name, 20, 0, 150, errbuf); if(dev){int j=20; printf("pcap_t: "); while(j--) printf("%02x ", *(j+(char*)dev)); printf("\n"); {int typ = pcap_datalink(dev); printf("link layer type: %d %s: %s\n", typ, pcap_datalink_val_to_name(typ), pcap_datalink_val_to_description(typ)); pcap_close(dev);}} else {perror("wont open! "); errbuf[PCAP_ERRBUF_SIZE]=0; printf("%s\n", errbuf);} pcap_addr_t * adrs = j-> addresses; for(; adrs; adrs = adrs -> next) printf("sa_family=%d ", (adrs -> addr) -> sa_family); printf("\n");} return(0);} // gcc ac.c -lpcap // sudo ./a.out /* 2009, Jan, Mac OS 10.5.6 Accessible interfaces are: network device name: en0, description: (null), pcap_t: 00 00 00 01 00 00 00 14 00 00 00 00 00 00 00 03 00 00 00 03 link layer type: 1 EN10MB: Ethernet sa_family=18 network device name: fw0, description: (null), pcap_t: 00 00 00 ffffff8a 00 00 00 14 00 00 00 00 00 00 00 03 00 00 00 03 link layer type: 138 APPLE_IP_OVER_IEEE1394: Apple IP-over-IEEE 1394 sa_family=18 network device name: en1, description: (null), pcap_t: 00 00 00 01 00 00 00 14 00 00 00 00 00 00 00 03 00 00 00 03 link layer type: 1 EN10MB: Ethernet sa_family=18 sa_family=30 sa_family=2 network device name: lo0, description: (null), pcap_t: 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 03 00 00 00 03 link layer type: 0 NULL: BSD loopback sa_family=18 sa_family=30 sa_family=2 sa_family=30 */