2013-06-13 2 views
0

없이 '방어 적이기'의 인수 2의 정수에서 포인터를하게 전달 : 경고 : 기본적으로 사용] 캐스트 다음 코드에 대한

/* get IP address on a specific network interface */ 
    void get_ip_dev(char* ipaddr, char* interface) 
    { 
      int fd; 
      struct ifreq ifr; 
      fd = socket(AF_INET, SOCK_DGRAM, 0); 
      ifr.ifr_addr.sa_family = AF_INET; 
      strncpy(ifr.ifr_name, interface, IFNAMSIZ-1); 
      ioctl(fd, SIOCGIFADDR, &ifr); 
      close(fd); 
      memcpy(ipaddr, inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr), 20); 
    } 

내가 memcpy에서 경고를받을 이유는 무엇입니까? 감사!

network.c: In function ‘get_ip_dev’: 
network.c:39:43: warning: passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default] 
/usr/include/string.h:44:14: note: expected ‘const void * __restrict__’ but argument is of type ‘int’ 

답변

2

간단한 픽스이어야합니다. <arpa/inet.h>을 포함해야합니다. 컴파일러는 아마도 int를 반환한다고 가정합니다.

+0

무엇을 포함할까요? – misteryes

+0

@misteryes 나는 나의 대답을 편집했다. 덕분에 – ctn

+0

! 'int'를 반환하는 것은 무엇입니까? – misteryes

0

두 번째 인수는 주소 위치로 예상되기 때문입니다. 귀하의 경우 그것은 가치 그 자체입니다.

관련 문제