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);
}