나는 누군가가 나에게 설명하기를 정말로 바라고있다. 기기의 MAC 주소를 사용하는 앱을 작성 중이며이 코드는 시뮬레이터에서 완벽하게 작동하지만 기기에서는 작동하지 않습니다.이 코드가 Xcode 시뮬레이터에서 작동하지만 장치에서 작동하지 않는 이유는 무엇입니까?
'net/if_types.h' file not found
그래서 내 질문입니다, 시뮬레이터에서 실행의 차이점은 무엇이 일어나고있는 이유와 :
나는 그것이 나에게주는 질문 Get router mac (without system call for ARP) in Objective-C#include <stdio.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
#include <net/if_types.h>
char* getMacAddress(char* macAddress, char* ifName)
{
int success;
struct ifaddrs *addrs;
struct ifaddrs *cursor;
const struct sockaddr_dl *dlAddr;
const unsigned char* base;
int i;
success = getifaddrs(&addrs) == 0;
if (success)
{
cursor = addrs;
while (cursor != 0)
{
const struct sockaddr_dl *socAddr =
(const struct sockaddr_dl *)cursor->ifa_addr;
_Bool afLinkFamily = (cursor->ifa_addr->sa_family == AF_LINK);
/* Ethernet CSMA/CD */
_Bool sdlIFTEther = (socAddr->sdl_type == IFT_ETHER);
if ((afLinkFamily) &&
sdlIFTEther &&
strcmp(ifName, cursor->ifa_name) == 0)
{
dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
base =
(const unsigned char*)&dlAddr->sdl_data[dlAddr->sdl_nlen];
strcpy(macAddress, "");
for (i = 0; i < dlAddr->sdl_alen; i++)
{
if (i != 0)
{
strcat(macAddress, ":");
}
char partialAddr[3];
sprintf(partialAddr, "%02X", base[i]);
strcat(macAddress, partialAddr);
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return macAddress;
}
오류에서이 코드를 가지고 장치? 미리 감사드립니다.
안녕하세요, 당신은 같은 문제에 직면 해있는 해결책이 있습니까? – Nikunj