How to get the MAC address of an external host in C ++

We are currently processing the output of the arp request from the command line.

string cmd = "arp -n ";
cmd.append(ipaddress);
cmd.append(" | grep ");
cmd.append(ipaddress);
fgets( line, 130, fp);
fgets( line, 130, fp);
ret.append(line);
 ...

It works, but is there a way to do this using a library function that will not depend so much on the command line interface? The project is currently using libpcap.

+3
source share
2 answers

In general, this will depend on your OS. There is no real standard API for this.

, Linux, /proc/net/arp. arp. , IP-, , , ARP, , , .

IP- - UDP - , - , .

arp, :) , arping ( , git repo ), , , , libpcap ( root)

+1

MAC-

.

, , ARP . , MAC- ARP. , MAC- , ( ).

, , , , , , , arp .

+1

Source: https://habr.com/ru/post/1707825/


All Articles