mac地址 linux c api,如何使用C程序获取linux中接口的mac地址?
有一個很棒的圖書館來管理以太網。
如果你想去低級別的東西,它當然值得學習。
學習C API是相當困難的。
Lib PCAP。
link to lib pcap sourceforge
一些示例代碼:
#include
#include
#include
#include
void find_eth_addr(struct in_addr *search_ip, const struct pcap_pkthdr* pkthdr, const u_char *packet) {
struct ether_header *eth_hdr = (struct ether_header *)packet;
if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) {
struct ip *ip_hdr = (struct ip *)(packet + sizeof(struct ether_header));
if (ip_hdr->ip_dst.s_addr == search_ip->s_addr)
print_eth_addr(eth_hdr->ether_dhost);
if (ip_hdr->ip_src.s_addr == search_ip->s_addr)
print_eth_addr(eth_hdr->ether_shost);
}
}還有像庫一樣好的“內核函數包裝器”:
DNET
它提供了在低級網絡上使用它的強大功能。
(也獲得MAC地址)。
DNET
有UNIX&贏得兩個圖書館的港口。
總結
以上是生活随笔為你收集整理的mac地址 linux c api,如何使用C程序获取linux中接口的mac地址?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux链接curl库,Linux利用
- 下一篇: Linux jupyter安装位置,Li