2012-04-05 3 views
3

나는 누군가가 나에게 설명하기를 정말로 바라고있다. 기기의 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; 
} 

오류에서이 코드를 가지고 장치? 미리 감사드립니다.

+0

안녕하세요, 당신은 같은 문제에 직면 해있는 해결책이 있습니까? – Nikunj

답변

1

iOS 기기 SDK에 헤더 파일이 누락되어 있습니다. 애플은 어떤 이유에서든 그것을 사용하기를 원하지 않습니다.

#include <net/if_types.h> 

완전히 라인

#define IFT_ETHER 0x6  /* Ethernet CSMACD */ 

를 제거 : 당신은 그냥 작동하도록 코드를 원한다면, 당신은 필요한 정의를 추출하기 위해 시도 할 수 있습니다. 이것은이 상수가 다른 값으로 정의 될 수있는 플랫폼과의 호환성을 파괴하지만.

+0

* "... 이것은이 상수를 다른 값으로 정의 할 수있는 플랫폼과의 호환성을 떨어 뜨리기는하지만"* - 글쎄,'/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/ SDKs/iPhoneOS6.1.sdk'는 전혀 정의되지 않았습니다. 그래서 그는 바위와 어려운 곳 사이에 있습니다. 그는 가능한 값 (예 : 0에서 10까지)을 반복하고 좋은 응답을 얻을 때까지 기다릴 수 있습니다. 일단 그가 좋은 반응을 얻으면 인터페이스 속성을 확인하여 미디어가 선호되는지 확인하십시오. – jww

관련 문제