October 22, 2024
Chicago 12, Melborne City, USA
C++

How can I get the destination MAC address of the node my macOS device is connected to in C?


So I’m implementing TCP sockets in C with raw sockets in order to further understand computer networking. I’m working on writing the ethernet header code, and I can get the source MAC address that’s burned onto my NIC with the getifaddrs, but I’m not sure how to get the destination MAC address. In FreeBSD which MacOS is based off of, it looks like you can use the ioctl syscall, but it seems MacOS removed the feature of getting the MAC address through that syscall. Is there some way of making an ARP request that’s common knowledge on MacOS that I don’t seem to be able to find any information about? The next best solution I’ve found is parsing the arp command, but that seems horribly inefficient to me and like there should be an easier way of doing this.

Any help would be much appreciated, I’ve spent a bit too much time scanning through ifconfig.c and random header files!



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video