1

When I am using socket programming to connect my iOS device to some devices (intelligent switch), I don't know how to obtain the MacAddress of the devices.

I know that the following code can work in Linux, but in Objective-C, there is no "SIOCGIFHWMAC" Parameter in ioctl() function and no "ifr_hwaddr" in struct ifreq. So, how can I obtain the MacAddress?

struct ifreq req;

memset(&g_CtrlAdpter, 0, sizeof(g_CtrlAdpter));

int Sock = socket(AF_INET, SOCK_DGRAM, 0);
memcpy(req.ifr_name, Device, strlen(Device));

int ErrNo = ioctl(Sock, SIOCGIFHWMAC, &req, sizeof(req));

if (-1 != ErrNo)
{
    memcpy(MACAddress, req.ifr_hwaddr, MAC_ADDR_LEN);
}
Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • You will probably have more luck querying the ARP table http://stackoverflow.com/questions/31226522/ios-get-arp-table – Paulw11 Nov 19 '15 at 05:49

0 Answers0