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’
무엇을 포함할까요? – misteryes
@misteryes 나는 나의 대답을 편집했다. 덕분에 – ctn
! 'int'를 반환하는 것은 무엇입니까? – misteryes