次のスニペットの場合:
/* 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’