/* Output eth0 mac address */ #include <dnet.h> #include <stdio.h> #include <stdlib.h> #include <memory.h> int main() { eth_addr_t eddr; unsigned char c[6]; memset(&eddr, 0, sizeof(eddr)); eth_t *eth = eth_open("eth0"); if (!eth) { printf("Failed to open interface -- eth0/n"); exit(1); } eth_get(eth, &eddr); memcpy(c, &eddr, sizeof(c)); printf("eth0 mac address: %02X:%02X:%02X:%02X:%02X:%02X/n", c[0], c[1], c[2], c[3], c[4], c[5]); return 0; } 需要root权限 /* Transmit raw ethernet frames */ #include <dnet.h> #include <stdio.h> #include <stdlib.h> #include <memory.h> int main() { char buf[50]; eth_t *eth = eth_open("eth0"); if (!eth) { printf("Failed to open interface -- eth0/n"); exit(1); } printf("%d/n", eth_send(eth, buf, sizeof(buf))); eth_close(eth); return 0; }