pcap_datalink函数
#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
char *dev = "eth0";
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle = pcap_create(dev, errbuf);
if (handle == NULL) {
fprintf(stderr, "Error creating pcap handle: %s\n", errbuf);
return 1;
}
if (pcap_activate(handle) == -1) {
fprintf(stderr, "Error activating pcap handle: %s\n", errbuf);
pcap_close(handle);
return 1;
}
int link_type = pcap_datalink(handle);
if (link_type == -1) {
fprintf(stderr, "Error getting datalink type\n");
pcap_close(handle);
return 1;
}
// 根据链路层类型标识符进行相应的处理
if (link_type == DLT_EN10MB) {
printf("The network interface uses Ethernet link layer protocol.\n");
} else {
printf("The network interface uses other link layer protocol with identifier: %d\n", link_type);
}
pcap_close(handle);
return 0;
}