gpt4 book ai didi

c - 警告 : passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default]

转载 作者:太空宇宙 更新时间:2023-11-04 08:55:52 29 4
gpt4 key购买 nike

对于以下片段:

    /* 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’

最佳答案

这应该是一个简单的修复:您需要包含 <arpa/inet.h> .编译器可能假设它返回 int。

关于c - 警告 : passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17077341/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com