Mac OS X에서 IP주소 확인하는 소스 코드를 사용중인데 WiFi일 때만 확인이 가능합니다. 뭐가 문제일까요?

willisone의 이미지

Mac OS X에서 IP주소 확인하는 소스 코드를 사용중인데 IP확인하는 함수는 KLDP에서 코드를 가져와서 살짝만 수정했고, 나머지 서브넷 주소 확인하는 프로그램도 인터넷에서 가져와서 수정하였습니다. 그런데 프로그램을 실행시키면 인터넷이 WiFi로 연결이 되었을 경우에만 IP주소를 잡아내고 thunderBolt 이더넷으로 연결을 할 경우에는 Network Device: en0 en0: no IPv4 address assigned Error 라고 메세지가 출력이 되네요. IP주소 얻어오는 함수 부분에서 strcpy 부분에서 썬더볼트 이더넷이 en5로 연결이 되길래 en5로 고쳐봤는데도 똑같은 메세지가 출력이 됩니다. 뭐가 문제일까요?

int get_ipconfig(uint *ipaddr) // Get IP Number
{
        int i, sock, ret;
        struct ifreq ifr;
 
        sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if (sock < 0) {
                printf("socket() error\n");
                return -1;
        }
 
        strcpy(ifr.ifr_name, "en0");
 
        // Get IP Adress
        ret = ioctl(sock, SIOCGIFADDR, &ifr);
        if (ret < 0) {
        printf("get_ipconfig(), ioctl() error\n");
        close(sock);
        return -1;
        }
        *ipaddr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
 
        return 0;
 
} //end of ipconfig
 
int main(int argc, char **argv)
{
        char *dev;    // using network device name
        char *mask;   // network mask address
        int ret;
        bpf_u_int32 maskp; // network device의 서브넷 마스크 주소가 저장될 주소
        bpf_u_int32 netp;
        unsigned int ipaddr;
        char *ip;
        char errbuf[PCAP_ERRBUF_SIZE]; //에러내용이 들어갈 장소
 
        struct sockaddr_in addr;
 
 
        dev=pcap_lookupdev(errbuf); // network device의 pointer return
        if(dev==NULL)
        {
                printf("%s Error\n",errbuf);
                exit(1);
        }
 
        addr.sin_addr.s_addr = maskp; // subnet mask 주소를 IP주소 처럼 ~.~.~.~ 형태로 바꿔줌
        mask = inet_ntoa(addr.sin_addr);
 
        if(mask == NULL)
        {
                perror("inet_ntoa");
                exit(1);
        }
 
        get_ipconfig(&ipaddr); // ip 주소 불러옴
        printf("MASK: %s\n",mask);
        addr.sin_addr.s_addr = ipaddr;
        ip = inet_ntoa(addr.sin_addr);
        printf("IP: %s\n", ip);
        return 0;
 
}//end of main

위에는 현재 코드입니다.

hardboiled65의 이미지

맥이 없어서 리눅스에서 빌드해봤는데 잘 됩니다. 일부러 엉뚱한 인터페이스를 집어넣어도 그런 메시지는 안 뜨길래 구글에 검색해보다가 이런 글을 발견했습니다.

https://discussions.apple.com/thread/1776609?tstart=0

주제는 좀 다른것 같지만 설정에서 IPv6 옵션을 끄라는 얘기가 있는데 혹시 썬더볼트 이더넷에 주소가 IPv6 전용으로만 할당되어있지 않나요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.